Has anyone successfully used a sql query to populate a...

Codes here !

Moderators: egami, macek, gesf

Post Reply

Mon Mar 17, 2003 10:34 am

:( Has anyone successfully used a sql query to populate a listbox in side of a $form variable? My code below works ok, except that the sql query does not populate the drop down box. I had a few suggestions, but nothing that worked. Can a sql query be put in a form variable? Below is the $form variable and the suggestions I have been given.

<?$form = "<form name=\"studentCreate\" method=\"post\" action=\"addStudent.php\">
<p>Enter Student's First Name: <input type=\"text\" name=\"sfname\" maxlength=\"30\" size=\"30\" value=\"$studentFirstName\"></p>
Assign Student to a Group:<select name=\"groupID\">
$listGroups_query = mysql_query(\"SELECT mathgroup.groupID, mathgroup.groupName from mathgroup\");
while($listGroups_record = mysql_fetch_array
($listGroups_query)) {
<option value=\"$listGroups_record[\"groupID"]"\">\"$listGroups_record[\"groupName"]\"</option>
I also tried this which was suggested:
<option value=\"".$listGroups_record["groupID"]."\">".$listGroups_record["groupName"]."</option>

<div align=\"right\"><input type=\"submit\" name=\"mode\" value=\"Submit\"></div>

The following code was suggested but creates a long list of errors, starting with the echo..then unexpected text strings etc.
<?$form=echo '<form name="studentCreate" method="post" action="addStudent.php">
<p>Enter Student's First Name: <input type="text" name="sfname" maxlength="30" size="30" value="'.$studentFirstName.'"></p>
Assign Student to a Group:
<select name="groupID">';
$listGroups_query = mysql_query("SELECT mathgroup.groupID, mathgroup.groupName from mathgroup");
while($listGroups_record = mysql_fetch_array($listGroups_query))
echo '<option value="'.$listGroups_record["groupID"].'">'.$listGroups_record["groupName"].'</option>';
echo '</select><br>
<div align="right"><input type="submit" name="mode" value="Submit"></div>

User avatar
Posts: 826
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Mon Mar 17, 2003 3:48 pm

Code: Select all

<select onchange="form.submit();" name="make[]">
      if(!$_POST['year'][$count]) $year = substr(date(Y),2,2);
      else $year = substr($_POST['year'][$count],2,2);
      $query = 'select make from vehicles where year like "%'.$year.'%" group by make order by make';
      $result = mysql_query($query);
      while($row = mysql_fetch_array($result))
      echo '<option value="'.$row['make'].'" ';
      if($_POST['make'][$count]==$row['make']) echo 'selected';
      echo '>'.$row['make'].'</option>'."\n";

hope that gives you more of an idea.

Post Reply