Jump to content

[SOLVED] How can I do this...not sure where to start


Recommended Posts

Hi,

I'd like to create a drop down menu that pulls first and last names from a database and when a name is selected all the records for that name are displayed. For example, I click the drop down and the following names appear:

  • John Abrams
  • Lisa Brown
  • John Cash
  • Joanne Stevens

...and I select Joanne Stevens ... then all the records for Joanne Stevens display. Is this possible and can someone point me in the right direction?

Thanks

make a xhtml form and use a select input type

 

strucutre your seleclt to be like

 

<select name="perrson">
<option value="0">John Abrams</option>
<option value="1">Lisa Brown</option>
....

process it via POST or GET and then that value is that person's ID for that table (or the parent to this child table) and then just query for that ID# very simple

Each record in the database will have a primary key id i.e.

 

1 John Abrams

2 Lisa Brown

3 John Cash

etc

 

Use this id as the value of the select list option. When the search button is clicked use the id to find the records you want:

 

SELECT * FROM table WHERE user_id='".$_POST['user_id']."'

 

so if I select Lisa the query comes out as:

 

SELECT * FROM table WHERE user_id='2'

 

Another option is to look into AJAX. (AJAX does not require a page re-load).

 

 

AJAX isn't another option for how to retrieve the data its a presentation method

 

Somewhere in the AJAX it still needs to pass a PK to a php processor to query the data from MySQL to return it to the AJAX function.

 

So AJAX just adjust how the POST data is sent and since the post going out is small its a good candidate for AJAX, but with this users experience starting smaller is probably better

 

 

That may be a bit complicated for this users level of experience

 

So what, I cannot inform them that it is an option?

 

@cooldude, maybe. However it is still a way to do a Dropdown list when you click on someone's name have their data display.

 

@both, granted I just mis-read the post, I thought he was looking at dual drop down lists (IE I select this name a new one is populated). But still, lay off. I did nothing wrong with informing him of another item he can later look into for populating data on his webpage.

That may be a bit complicated for this users level of experience

 

So what, I cannot inform them that it is an option?

 

@cooldude, maybe. However it is still a way to do a Dropdown list when you click on someone's name have their data display.

 

@both, granted I just mis-read the post, I thought he was looking at dual drop down lists (IE I select this name a new one is populated). But still, lay off. I did nothing wrong with informing him of another item he can later look into for populating data on his webpage.

 

When I make a silly statement feel free to rip into my no one learns if they just think everything is right. 

 

AJAX is usually misused as a "hot" term and it annoys me when ppl just put AJAX without an explanation because it is actually much more complicated than most ppl think.

 

Most of the time you have very good results just didn't want to see a new person confused was all

 

Most of the time you have very good results just didn't want to see a new person confused was all

 

No worries. I am just a little moody today, and yea.

 

The reasoning for just posting "AJAX" was that I figured he was a beginner and if he wanted to learn it, it is better to search for it. At least he now knows the terminology.

 

Anyhow, it was my bad in that I completely mis-read the post (and probably did not supply sufficient data with it). He was just asking for data to post/populate data and never specified a page-refresh, which ajax would not be affiliated with.

make a xhtml form and use a select input type

 

strucutre your seleclt to be like

 

<select name="perrson">
<option value="0">John Abrams</option>
<option value="1">Lisa Brown</option>
....

process it via POST or GET and then that value is that person's ID for that table (or the parent to this child table) and then just query for that ID# very simple

 

I'd like the select values themselves to be populated from the database(I have over 400 names so I don't want to have to type each name in) this is what I wasn't sure how to do.

Something like

<?php 
$q = "Select Whateverfields from `table` Order by Name";
$r = mysql_query($q) or die(mysql_error()."<br /><br />">$q);
echo "<select name='name'>";
while($row = mysql_fetch_assoc($r)){
echo "<option value='".$row['id']."'>".$row['Name']."</option>";
}
echo "</select>";
?>

 

 

General idea

 

Something like

<?php 
$q = "Select Whateverfields from `table` Order by Name";
$r = mysql_query($q) or die(mysql_error()."<br /><br />">$q);
echo "<select name='name'>";
while($row = mysql_fetch_assoc($r)){
echo "<option value='".$row['id']."'>".$row['Name']."</option>";
}
echo "</select>";
?>

 

 

General idea

 

That's what I was looking for - thanks for all your help

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.