Dropdown combo

5 posts Page 1 of 1
Contributors
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Dropdown combo
Mark
Hello can anyone help me please i use the following code to display my table in the drop down box when i select a name how can i get it to show the rest of the record for that person?

PHP Code:
Code: Select all
<select name="select"> 
<option id="0">---------- SELECT YOUR CUSTOMER NAME ----------</option> 
<?php 
require("db.php"); 
$getallCustomers = mysql_query("SELECT * FROM customers"); 
while($viewallCustomers = mysql_fetch_array($getallCustomers)){ 
?> 

<option id="<?php echo $viewallCustomers['name_id']; ?>"><?php echo $viewallCustomers['name'] ?></option> 
<?php } ?> 
</select>
Thanks

Mark
http://www.mbappz.com
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Dropdown combo
Filip
Hey,

you would want to change id="" of each option to value="" and then process it just as any regular form.

KR,
-Filip
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Dropdown combo
Filip
Hello,

Mark asked me to do a sample code in PM, so here it is, so everyone can see it:
Code: Select all
<form action="where/to/submit.php" method="get">
<select name="select"> 
<option value="0">---------- SELECT YOUR CUSTOMER NAME ----------</option> 
<?php 
require("db.php"); 
$getallCustomers = mysql_query("SELECT * FROM customers"); 
while($viewallCustomers = mysql_fetch_array($getallCustomers)){ 
?> 

<option value="<?php echo $viewallCustomers['name_id']; ?>"><?php echo $viewallCustomers['name'] ?></option> 
<?php } ?> 
</select>
<input type="submit" value="Show records" />
</form>

And then, on submit.php or whatever you call it, following should be done:
Code: Select all
<?php
$customer_id = (isset($_GET['select'])) ? $_GET['select'] : die('No customer id selected');

// do something with $customer_id
KR,
-Filip
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: Dropdown combo
Mark
Hi,

Thanks all i really wanted to do is make a table called customers with field name id and full name and address

in the dropdown box i want to display the persons full name and when i select a name from the drop down box it then shows me the information for that persons name from the database?
http://www.mbappz.com
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Dropdown combo
Filip
And that's what should be done by submit.php.. It will obtain the id selected from dropdown and based on that, it should use $customer_id to query the database. The query should be something like
Code: Select all
SELECT * FROM customers WHERE id=$customer_id
After you run that query, displaying record shouldn't be that hard and I'm sure you've done it before.

Also I don't understand if you're trying to load customer data asynchronously using AJAX?

KR,
-Filip
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
5 posts Page 1 of 1
Return to “Help & Support”