Jump to content

Button to Populate List Box


DSTR3

Recommended Posts

I have a button. When I click on the button I want to populate a listbox in AS order. (I would like the listbox to start out blank. Then when the button is clicked, the listbox populates. I have this so far, but when I open the page the box is already populated and the order is far from ASC. Any help s appreciated. Thank you.

 

<?php
try {

$objDb = new PDO('mysql:host="";dbname=""', '', [email="'@1973'"]'[/email]);
$objDb->exec('SET CHARACTER SET utf8');

$sql = "SELECT * FROM `tblRestaurants` WHERE `RestStatus` = 'YES' ORDER BY 'RestName' ASC";
$statement = $objDb->query($sql);
$list = $statement->fetchAll(PDO::FETCH_ASSOC);

} catch(PDOException $e) {
echo 'There was a problem';
}
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>First Box</title>
<meta name="description" content="First Box" />
<meta name="keywords" content="First Box" />
<link href="/BigStuff/css/core.css" rel="stylesheet" type="text/css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>

<div id="wrapper">
   <div align="center">
  <form name="form1" method="post" action="">
    <div align="left">First Box
    <input type="submit" name="First Box" id="First Box" value="Submit">

	 <select name="Place" size="25" id='Place' class="update">
	  <option value="">Select one</option>
	  <?php if (!empty($list)) { ?>
	  <?php foreach($list as $row) { ?>
	  <option value="<?php echo $row['RestID']; ?>">
	    <?php echo $row['RestName']; ?>
	  </option>
	  <?php } ?>
	  <?php } ?>
    </select>
</div>

<script src="/BigStuff/js/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="/BigStuff/js/core.js" type="text/javascript"></script>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/272967-button-to-populate-list-box/
Share on other sites

Thank you for your reply. But how do I stop my listbox from loading, and how do I add the button? I am new to all of this, so your help by example would be greatly appreciated! Thank you, once again. Also I greatly reduced the code to make this whole thing clearer.

 

<?php
$dbc = mysql_connect('', '',')
 or die('Error connecting to MySQL server.');
mysql_select_db('');
$result = mysql_query("select * from tblRestaurants order by RestName ASC");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MENUHEAD</title>

</head>
<body>

<p><center>SEARCH</CENTER></P>
<select name="RestName">
<?php
while ($nt= mysql_fetch_assoc($result)) 
{
 echo '<option value="' . $nt['RestID'] . '">' . $nt['RestName'] . '</option>';
} 
?>
</select>

<p>Click "SUBMIT" to display the calculation results</p>
<input type="submit" name="Submit" value="Submit" />
<br />

</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.