Jump to content

[SOLVED] simple syntax error...


Derleek

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.