NeoAshura
asked on
PHP DROP DOWN POPULATED BY MYSQL
Hello Experts,
Thank you for your time,
Im really stuck here, What im after is a PHP drop down box which is populated from my MYSQL database. this database could consist of the following.
Asda
Tesco
Morrisons
Sainsburys
etc etc
The drop down needs to "select * from company" and place it into the drop down menu to be selected.
a button is then clicked which posts the selected STORE into the next page where it is SEARCHED for in the database and the STORE details are then listed inside a new page.
The Store details would be located in another table for example.
Company_address
Asda 13 Leeds court
Tesco blah blah
You get the picture... based on the entry selected the following store address must be returned.. and none of the others..
Is this possible??
Many thanks
All input is appricated.
James
Thank you for your time,
Im really stuck here, What im after is a PHP drop down box which is populated from my MYSQL database. this database could consist of the following.
Asda
Tesco
Morrisons
Sainsburys
etc etc
The drop down needs to "select * from company" and place it into the drop down menu to be selected.
a button is then clicked which posts the selected STORE into the next page where it is SEARCHED for in the database and the STORE details are then listed inside a new page.
The Store details would be located in another table for example.
Company_address
Asda 13 Leeds court
Tesco blah blah
You get the picture... based on the entry selected the following store address must be returned.. and none of the others..
Is this possible??
Many thanks
All input is appricated.
James
With the code snippets above and a quick look through this tut here (http://www.tizag.com/mysqlTutorial/index.php) you'll be up and running in no time.
ASKER
thanks pats, i tried your code and nothing was clickable in the drop down..
any ideas why code is attached.
any ideas why code is attached.
<?php
error_reporting(E_ALL);
include 'myphp.php';
?>
<select id="ddlCompanies">
<?php
$sql = "SELECT title FROM 'companies' ORDER BY title";
$rs = mysql_query($sql);
while($row = mysql_fetch_array($rs)) {
echo ("<option>" . $row['title'] . "</option>");
}
?>
</select>
<br />
<input type="button" onclick="var val = document.getElementById('ddlCompanies').options[document.getElementById('ddlCompanies').selectedIndex].value; var url = 'companyInfo.php?val=';url+=val;window.location=url;" value="Submit..." />
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
cheers works now as in i can select stuff but when i click go it returns following error code is attatched..
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\companyInfo.ph p on line
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\companyInfo.ph
ASKER
code
<?php
error_reporting(E_ALL);
include 'myphp.php';
$val = $_GET['val'];
$sql = "SELECT store_address, store_phone FROM stores WHERE store_name = '" . $val . "'";
$rs = mysql_query($sql);
while($row = mysql_fetch_array($rs))
{
echo('Address: ' . $row['store_address']);
echo('Phone: ' . $row['store_phone']);
}
?>
ASKER
my bad two secs
ASKER
You sir are a legend 10/10 good instructions quick too.
Glad to help!
Cheers
Cheers
Open in new window
Then to get the selected info from the db you could do something like this using the selected value from the URL parameter in the companyInfo.php page like this:
Open in new window