Hi!,
I have a contacts table in MySQL and I want output in a select menu.
Problem is, some rows dont have any record in it, and it is displayed in very odd way as it outputs blank fields and some data in between.

My overall code is:

<?PHP
$query=mysql_query("SELECT * FROM call_details WHERE !ISNULL(call_project_name)");
echo "<select name='detailr'>";
while($row=mysql_fetch_array($query))
{
echo "<option value=$row[call_id]>
$row[call_project_name]</option>";
}
echo "</select>";
?>

Please help me out in this matter :(

Hi,
try the below code, you will got it.

<?PHP

$query = mysql_query("SELECT * FROM call_details WHERE !ISNULL(call_project_name)");

echo "<select name='detailr'>";

while($row=mysql_fetch_array($query))
{
    if ($row['call_project_name'] != " "){
       echo "<option value =". $row['call_id'].">".
       $row['call_project_name']."</option>";
    }
}
echo "</select>";
?>

Unfortunately same result is displaying.

Try this.

<?PHP
$query=mysql_query("SELECT * FROM call_details WHERE !ISNULL(call_project_name)");
echo "<select name='detailr'>";
while($row=mysql_fetch_array($query))
{
echo "<option value='$row[call_id]'>".$row."</option>";
}
echo "</select>";
?>

$query = mysql_query("SELECT * FROM call_details WHERE !ISNULL(call_project_name)");
echo "<select name='detailr'>";
while($row = mysql_fetch_array($query))
{
   if (!empty(trim($row['call_project_name'])))
   {
      echo "<option value='{$row['call_id']}'>{$row['call_project_name']}</option>";
   }
}
echo "</select>";
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.