Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

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

Codes here !

Moderators: macek, egami, gesf

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

Postby lsg3385 » 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>
}

</select><br>
<div align=\"right\"><input type=\"submit\" name=\"mode\" value=\"Submit\"></div>
</form>";
?>

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>
<p></p>
<div align="right"><input type="submit" name="mode" value="Submit"></div>
</form>';
?>
lsg3385
New php-forum User
New php-forum User
 
Posts: 5
Joined: Fri Mar 14, 2003 5:35 pm

Postby Redcircle » Mon Mar 17, 2003 3:48 pm

Code: Select all
<select onchange="form.submit();" name="make[]">
                 <?php
      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";
      }
      ?>
                    </select>


hope that gives you more of an idea.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA


Return to mySQL & php coding

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.