kevinritt Posted February 24, 2009 Share Posted February 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/ Share on other sites More sharing options...
cooldude832 Posted February 24, 2009 Share Posted February 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770186 Share on other sites More sharing options...
JonnoTheDev Posted February 24, 2009 Share Posted February 24, 2009 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' Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770187 Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 Another option is to look into AJAX. (AJAX does not require a page re-load). Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770189 Share on other sites More sharing options...
JonnoTheDev Posted February 24, 2009 Share Posted February 24, 2009 That may be a bit complicated for this users level of experience Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770192 Share on other sites More sharing options...
cooldude832 Posted February 24, 2009 Share Posted February 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770196 Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770207 Share on other sites More sharing options...
cooldude832 Posted February 24, 2009 Share Posted February 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770211 Share on other sites More sharing options...
MatthewJ Posted February 24, 2009 Share Posted February 24, 2009 wow... somebody must need another cup of coffee Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770212 Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770213 Share on other sites More sharing options...
kevinritt Posted February 24, 2009 Author Share Posted February 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770216 Share on other sites More sharing options...
cooldude832 Posted February 24, 2009 Share Posted February 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770227 Share on other sites More sharing options...
kevinritt Posted February 24, 2009 Author Share Posted February 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/146698-solved-how-can-i-do-thisnot-sure-where-to-start/#findComment-770290 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.