• Top Members
    Reps
    Posts
  • 834 Replies
    2585 Replies
  • 716 Replies
    2025 Replies
  • 331 Replies
    1928 Replies

Dropdown combo

User avatar
Mark
VIP - Donator
Posts: 370

Dropdown combo

Mon May 23, 2016 3:55 pm

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

User avatar
Filip
Coding Guru
Posts: 833

Re: Dropdown combo

Tue May 24, 2016 8:44 am

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

User avatar
Filip
Coding Guru
Posts: 833

Re: Dropdown combo

Tue May 24, 2016 11:52 am

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
Posts: 370

Re: Dropdown combo

Tue May 24, 2016 12:15 pm

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?

User avatar
Filip
Coding Guru
Posts: 833

Re: Dropdown combo

Tue May 24, 2016 11:40 pm

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

Post Reply

Return to “Help & Support”