dev1902 Posted July 31, 2013 Share Posted July 31, 2013 Hello, I working on my code to populate a text field from a column of data in a mysql database and i was successful. -- I don't know if this is the best code to do so. Check it out!! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="generator" content="Adobe GoLive" /> <title>Test site</title> </head> <body> <form action="index.php" method="post" name="sampleDetail" target="_self" class="container" AUTOCOMPLETE="off"> <label for="sampleID">Gene 1: </label> <input type="text" name='sampleID' id='sampleID' list="samp"> <br><br> <datalist id="samp"> <?php $connect = mysql_connect("localhost", "root", ""); mysql_select_db("csv_db"); $query = mysql_query("SELECT * FROM `gene_name` ORDER BY `gene_name`.`COL 2` ASC LIMIT 2, 6970"); WHILE ($rows = mysql_fetch_array($query)): $Column_2 = $rows['COL 2']; echo "<option value=$Column_2>$Column_2</option> <br>"; endwhile; ?> </datalist> <label for="sampleID">Gene 2: </label> <input type="text" name='sampleID' id='sampleID' list="samp"> <br><br> <datalist id="samp"> <?php $connect = mysql_connect("localhost", "root", ""); mysql_select_db("csv_db"); $query = mysql_query("SELECT * FROM `gene_name` ORDER BY `gene_name`.`COL 2` ASC LIMIT 2, 6960 "); WHILE ($rows = mysql_fetch_array($query)): $Column_2 = $rows['COL 2']; echo "<option value=$Column_2>$Column_2</option> <br>"; endwhile; ?> </datalist> <input type="button" value="Submit"> </form> </body> </html> Do have any suggestions? I also want to make sure i can type in the same gene with different. This is how it would look in the row: c15of1v | B10of1d | R12of1g -- All three names are listed in the same row. I want to be able to type in either of those names and get the same gene. Is that possible? Quote Link to comment https://forums.phpfreaks.com/topic/280685-few-quick-inquiries/ Share on other sites More sharing options...
PravinS Posted August 6, 2013 Share Posted August 6, 2013 there is no need to open multiple database connections, you can use one common file say dbconn.php, write database connection code in it and include that file whereever you want to use database queries Quote Link to comment https://forums.phpfreaks.com/topic/280685-few-quick-inquiries/#findComment-1443621 Share on other sites More sharing options...
cyberRobot Posted August 6, 2013 Share Posted August 6, 2013 Are the datalists for Gene 1 and Gene 2 supposed to be the same? If so, you could use a single query to grab the list, store it in a variable, and use the variable to populate the datalists. Also, you probably don't need to create the $Column_2 variable in the while loop. You could just use the $rows variable: <?php echo "<option value={$rows['COL 2']}>{$rows['COL 2']}</option> <br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/280685-few-quick-inquiries/#findComment-1443667 Share on other sites More sharing options...
mac_gyver Posted August 7, 2013 Share Posted August 7, 2013 (edited) you mentioned typing in information. you would only want to type ORIGINAL information when you first enter it into your database. if you already have information in a database, you would use some sort of menu to let the user pick it. you apparently are trying to do this using a select/option menu, but your html is missing the <select name='...'></select> tags and the form input fields you do have both have the same name='...' attribute so only the last field will be submitted. the LIMIT clause in your query(ies) also raises questions. it is skipping over the first two rows and NO one would look at or scroll over 6000+ entries on a page. you would present some sort of search/category/type-a-head-lookup to present a smaller set of choices. have you defined exactly what you want for a user interface, before trying to write any of the code for it? using column names (and variables) like COL 2 also isn't going to get you much sympathy or help on programming forums. you need to use names that convey the meaning of the data, so that you or anyone else that might need to look at your code/queries can determine the intent. Edited August 7, 2013 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/280685-few-quick-inquiries/#findComment-1443819 Share on other sites More sharing options...
Solution dev1902 Posted August 8, 2013 Author Solution Share Posted August 8, 2013 Thanks for the advice, but i fixed my problems the same day i posted this. Quote Link to comment https://forums.phpfreaks.com/topic/280685-few-quick-inquiries/#findComment-1443992 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.