Derleek Posted May 28, 2008 Share Posted May 28, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/107706-solved-simple-syntax-error/ Share on other sites More sharing options...
DarkWater Posted May 28, 2008 Share Posted May 28, 2008 You need a space here: <?php } ?> I think, at least. Try it. Quote Link to comment https://forums.phpfreaks.com/topic/107706-solved-simple-syntax-error/#findComment-552143 Share on other sites More sharing options...
Derleek Posted May 28, 2008 Author Share Posted May 28, 2008 see? told ya it was simple been at this all day... i need a break... thanks a bunch Quote Link to comment https://forums.phpfreaks.com/topic/107706-solved-simple-syntax-error/#findComment-552144 Share on other sites More sharing options...
.josh Posted May 28, 2008 Share Posted May 28, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/107706-solved-simple-syntax-error/#findComment-552147 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.