Jump to content

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>

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.