Ok, I feel like I'm so close, but could use some help. I am trying to retrieve data from mySQL database via use of a form with checkboxes. This form is working somewhat except that it is only pulling one selection, not all that are selected. Can someone look at this and let me know how to fix this? Would greatly appreciate it!!

<html>
<head>
<title>Checkbox retrieval test</title>
</head>
<body>

<form method='post'>
<input type=checkbox name=fc[] value="red" class=2> red<br> 
<input type=checkbox name=fc[] value="yellow" class=2> yellow<br> 
<input type=checkbox name=fc[] value="orange" class=2> orange<br> 
<input type=checkbox name=fc[] value="burgundy" class=2> burgundy<br> 
<input type=submit name=submit> 
</form> 

<? 

if(isset($_POST['submit'])) 
{ 
  foreach($_POST['fc'] As $fc) 
    printf("%s<br>", $fc); 
} 

$fcList = "";

foreach($_POST['fc'] As $fc) 
$fcList .= $fc . " ";

 
// Make a MySQL Connection
	mysql_connect("", "", "") or die(mysql_error());
	mysql_select_db("") or die(mysql_error());


$query = "SELECT * FROM findplantsdb WHERE Color='$fc'";


$result= mysql_query($query); 
$num_results = mysql_num_rows($result); 

for ($i=0; $i <$num_results; $i++) 
{ 
$row = mysql_fetch_array($result); 


echo "<h4> ", $row['Name'], " &nbsp; ", $row['Patent'], "</h4> ",$row['Common'], "<p> Height:  ", $row['Hname'], "<br> Spread:  ", $row['Sname'], "<br> Color:  ", $row['Color'], "<br> Light:  ", $row['Light'], "<br> Zone:  ", $row['Zone'], "<p> <img src=http://www.domain.com/mobile/",$row['Picname'],  " /> <p><p>", $row['Notes'], "<p><p> <hr width='50%' size='1' color='#A3A3A3'> <p>";
} 

  
?> 
 
</body>
</html>
Member Avatar
diafol

just a quick look try changing this:

for ($i=0; $i <$num_results; $i++) 
{ 
$row = mysql_fetch_array($result); 
 
 echo "<h4> ", $row['Name'], " &nbsp; ", $row['Patent'], "</h4> ",$row['Common'], "<p> Height:  ", $row['Hname'], "<br> Spread:  ", $row['Sname'], "<br> Color:  ", $row['Color'], "<br> Light:  ", $row['Light'], "<br> Zone:  ", $row['Zone'], "<p> <img src=http://www.domain.com/mobile/",$row['Picname'],  " /> <p><p>", $row['Notes'], "<p><p> <hr width='50%' size='1' color='#A3A3A3'> <p>";

}

to:

while($row = mysql_fetch_array($result)) 
{ 
echo "<h4> ". $row['Name']. " &nbsp; ". $row['Patent']. "</h4> ".$row['Common']. "<p> Height:  ". $row['Hname']. "<br> Spread:  ". $row['Sname']. "<br> Color:  ". $row['Color']. "<br> Light:  ". $row['Light']. "<br> Zone:  ". $row['Zone']. "<p> <img src=http://www.domain.com/mobile/".$row['Picname'].  " /> <p><p>". $row['Notes']. "<p><p> <hr width='50%' size='1' color='#A3A3A3'> <p>";

}

All I've done is change the , for a .
However, the html markup in the loop is a little odd. Don't usually place <p><p> together. Also <br /> instead of <br> these days - although it'll still work.