Jump to content

listbox only showing 1 ?!


illuz1on

Recommended Posts

hey

 

I have a listbox called "I want to..." and people select in the listbox what they want to do and then the selection links to x.php ... This code only shows 1 entry in the listbox while the database has more

 

<?php
include("db.php");
?>
<html>
<body>
<?php
//select statement example ok all book entry's lol.
$sql = "SELECT * FROM guides";
$data = mysql_query($sql);
while($record = mysql_fetch_assoc($data)) {

$id = $record['id'];
$name = $record['name'];
$link = $record['link'];
   
}
echo "<form name=\"guideform\" id=\"guideform\" action=\"#\"> 
<select name=\"guidelinks\" id=\"guidelinks\" onChange=\"window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value\"> 
<option selected value=\"#\">I want a</option> 
<option value=\"$link.php\">$name</option>
</select> 
</form> ";
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/48757-listbox-only-showing-1/
Share on other sites

you are missing a loop. fundamental in outputting numerous records form a database...

 

Don't be scared to break out of php, its no big deal...

 

<?php
include("db.php");
?>
<html>
<body>
<?php
//select statement example ok all book entry's lol.
$sql = "SELECT * FROM guides";
$data = mysql_query($sql);
   
}
?>
<form name="guideform" id="guideform" action="#"> 
<select name="guidelinks" id="guidelinks" onChange="window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value"> 
<option selected value="#">I want a</option> 
<?php
while($record = mysql_fetch_assoc($data)) {
echo '<option value="'.$record['link'].'">'.$record['name'].'</option>';
}
?>
</select> 
</form>
</body>
</html>

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.