Jump to content

Few Quick Inquiries


Go to solution Solved by dev1902,

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/280685-few-quick-inquiries/
Share on other sites

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>";
?>
Link to comment
https://forums.phpfreaks.com/topic/280685-few-quick-inquiries/#findComment-1443667
Share on other sites

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 by mac_gyver
Link to comment
https://forums.phpfreaks.com/topic/280685-few-quick-inquiries/#findComment-1443819
Share on other sites

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.