I have a drop-down list box which has to be populated from a database in mysql. I implemented the following code:

//DB Conn done here..
<td>College Name,id :</td>
<td><select><option selected="selected">Choose a college...</option>
<?php
$query="SELECT nameid from college";
$result=mysql_query($query);
while ($line = mysql_fetch_array($result))
{
	foreach ($line as $value)
	{
	echo "<OPTION value='$value'";
	}
echo ">$value</OPTION>";
}
mysql_close($link);
print "</SELECT>";
?>
</select>
</td>

My problem is a new line is inserted between each entry in the drop-down list box. Pls help me to remove that empty line.

hey there hari!

try this :

<td>College Name ID :</td>
										<td><select name="collegeName" width = "200">
											<option value=''> Choose a college : </option>
											
											<?php
				
												$myquery=mysql_query("SELECT distinct nameid from college");
																		
													if(mysql_fetch_object($myquery) == null)
													{
														echo "<option value=''> No Record Found. </option>";
													}
																		
													else
													{	
																		
														$myquery=mysql_query("SELECT distinct nameid from college");	
																									
														while($collname=mysql_fetch_object($myquery))
														{
															echo "<option value='$collname->nameid'>".$collname->nameid."</option>";
														}
													} 
													
											?>
											
										</select></td>

i hope this helps .:)

Hey thanks for the help ﻼim. It works :)

Hey thanks for the help ﻼim. It works :)

no problem. :$
it's great to help you out with that.

don't forget to mark this thread as solved.
good luck! Ϋ
and happy day ahead!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.