Reputation: 79
I will get right to it, I am having a small difficulty with my php code provided below. I have 10 form fields connected to my mysql database, the code below basically grabs existing data that has been submitted in the form fields named "item1, item2, item3, etc... and displays it in the select form field once clicked. This code repeats for an additional 9 form fields. See below:
<?php
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." GROUP BY status ORDER BY status";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
while ($row = mysql_fetch_assoc($sql_result)) {
echo "<option value='".$row["item1"]."'".($row["item1"]==$_REQUEST["item1"] ? " selected" : "").">".$row["item1"]."</option>";
}
?>
if ($_REQUEST["item1"]<>'') {
$search_item1 = " AND item1='".mysql_real_escape_string($_REQUEST["item1"])."'";
}
When I fill out, let's say 3 of 10 form fields, leaving 7 empty, the empty values are displayed in the select form field once i click on the select field. I have provided a picture to show what I'm talking about. See below:
I need the empty values to stop adding an empty space in these fields, if someone could help me with this it would be much appreciated.
Thx.
Upvotes: 0
Views: 249
Reputation: 2124
I think you can limit that by adding WHERE item1 != ''
Or if the field contains white space than you can use:
if (!empty(trim($row["item1"])))
{
echo "<option value='".$row["item1"]."'".($row["item1"]==$_REQUEST["item1"] ? " selected" : "").">".$row["item1"]."</option>";
}
Upvotes: 2