Jump to content

Recommended Posts

creating a dynamic drop down menu... first time i've attempted it.  The array's are loaded from a file.

 

here is all of the code, when i comment out the foreach loop section it runs so i'm guessing its in that area of the code

 

<?php dbConnect('thethrgu_moto');
$query = "SELECT * FROM Racers"; 

$result = mysql_query($query) or die(mysql_error());

$R_id = array();
$rider = array();
$x=0;
while($row = mysql_fetch_array($result)){
$R_id[$x]= $row['number'];
$rider[$x]= $row['name'];
echo "R_ID: {$R_id[$x]}<br>";
echo "rider: {$rider[$x]}<br>";
$x++;
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
	<select name="choices[]">
		<option value="null">---</option>
		<?php foreach($rider as $key => $name)
		{
			?><option value="<?php echo $R_id[$key];?>"><?php echo $name;?></option>
		<?php}?>
		</select>
	<br>
	<br>

 

i'm sure its simple, i just am not familiar with how to load up a drop down menu with php variables... it seems like it should work to me!  (then again... i'm no pro ;)

Link to comment
https://forums.phpfreaks.com/topic/107706-solved-simple-syntax-error/
Share on other sites

I don't really see why those two loops can't be combined...

 

<?php 
   dbConnect('thethrgu_moto');
   $query = "SELECT * FROM Racers"; 
   $result = mysql_query($query) or die(mysql_error());
?>

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
   <select name="choices[]">
      <option value="null">---</option>

<?php
   while($row = mysql_fetch_array($result)){
      echo "<option value = '{$row['number']}'>{$row['name']}</option>";
   }
?>
   </select>
<!-- </form>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.