zenix Posted September 29, 2009 Share Posted September 29, 2009 Hello, I am trying to learn php and mysql, and making pretty good progress. I've developed a database for a make believe company and have it working correctly. I thought it'd be neat to have the data (such as last name, first name and phone) appear in a text area at the top or bottom of the form that I use to enter/modify and view my data. I'd like to make it so I can click on an entry in the text area and have the fields of the form populate with the relevant data. Someone mentioned I should use a drop down. I've tried this, I get the info into the drop down alright, but don't know how to go about making the data clickable so the info. fills out the form on the page. I think I'd really prefer a scrolling text area though, but when I try THIS approach I keep getting an error stating that the ...mysql_fetch_array ($result) is not a valid MySQL entry. If someone could help me out, I'd really appreciate it. I've learned a lot this year, apparently I have quite a ways to go. Here is the code I have for the drop down. <?php include("connect.php"); $result = mysql_query("SELECT lname, fname, phone FROM warrantydb ORDER BY lname ASC"); echo "<select name=\"DropData\">"; while($row = mysql_fetch_array( $result )) { //I figure there is a more refined way of doing this, but this works for me. Any thoughts would be appreciated. $Data=$row['lname']; $Data2=$row['fname']; $Data3=$row['phone']; echo "<option>$Data $Data2 $Data3</option>"; } echo "</select>"; ?> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted September 29, 2009 Share Posted September 29, 2009 You need to some way add an identifier into the options. If you have an "id" field in the warrantydb table you can modify your query for this: SELECT id,lname, fname, phone FROM warrantydb ORDER BY lname ASC Now assign this into a variable: $id=$row['id']; Now, when you add the options, use this line: echo "<option value=\"$id\">$Data $Data2 $Data3</option>"; Now read the id field... POST: $warrantyid=$_POST['DropData']; GET: $warrantyid=$_GET['DropData']; Quote Link to comment Share on other sites More sharing options...
zenix Posted September 29, 2009 Author Share Posted September 29, 2009 I appreciate all your time and assistance on this, thank you. I tried your example and although it allows me to select an option from the drop down, I don't know how to get all the data associated with this person to be displayed in the form. I have the form all set up and working well, it includes address, address2 city, state and zip, is there a way to have this information populated in the correct fields for the person chosen? Thank you so much again!! Quote Link to comment Share on other sites More sharing options...
Yesideez Posted September 29, 2009 Share Posted September 29, 2009 When you get the id from the warrantydb table you can use this to then pull data from the database. Quote Link to comment Share on other sites More sharing options...
zenix Posted September 29, 2009 Author Share Posted September 29, 2009 Thank you for all your guidance, I'll try figuring it out from what you said. You have been a big help to me! Quote Link to comment 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.