SEVIZ Posted March 20, 2009 Share Posted March 20, 2009 I am using this code: <select name='tech' id='tech' tabindex='2'> <option value='select'>TEAM CRONIN</option> <?php // Make a MySQL Connection mysql_connect("localhost", "****", "****") or die(mysql_error()); mysql_select_db("****") or die(mysql_error()); $result = mysql_query("SELECT * FROM tech WHERE TEAM='".CRONIN."'") or die(mysql_error()); while ($row = mysql_fetch_array($result)){ $ID = $row['ID']; echo "<option value=".$ID.">$ID</option>"; } ?> <option value='select'>TEAM DENIS</option> <?php // Make a MySQL Connection mysql_connect("localhost", "****", "****") or die(mysql_error()); mysql_select_db("****") or die(mysql_error()); $result = mysql_query("SELECT * FROM tech WHERE TEAM='".DENIS."'") or die(mysql_error()); while ($row = mysql_fetch_array($result)){ $ID = $row['ID']; echo "<option value=".$ID.">$ID</option>"; } ?> </select> How can I do this but without having to query again each time? I have 12 total of these seperate sections and do not want that many queries. EEK! Thanks for any help as always! Link to comment https://forums.phpfreaks.com/topic/150247-not-have-to-keep-doing-a-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 20, 2009 Share Posted March 20, 2009 See items A), B), and D) (replace reference to "month" name with "team" name) at this link - http://www.phpfreaks.com/forums/index.php/topic,242980.msg1134556.html#msg1134556 Link to comment https://forums.phpfreaks.com/topic/150247-not-have-to-keep-doing-a-query/#findComment-789042 Share on other sites More sharing options...
SEVIZ Posted March 20, 2009 Author Share Posted March 20, 2009 Thank you for the help but I must be misunderstanding something. Everything I try with this comes out wrong or weird. I know this is probably asking a lot but can you elaborate at all on what the stuff in that code does? So much of it is related to date and such and mine does not have that at all. I am lost trying to figure it out. I apologize. Link to comment https://forums.phpfreaks.com/topic/150247-not-have-to-keep-doing-a-query/#findComment-789052 Share on other sites More sharing options...
DarkWater Posted March 20, 2009 Share Posted March 20, 2009 First of all, you're make a new connection each time. You could just do: <select name='tech' id='tech' tabindex='2'> $result = mysql_query("SELECT * FROM tech") or die(mysql_error()); while ($row = mysql_fetch_array($result)){ $name = $row['TEAM']; $id = $row['ID']; echo "<option value='$id'>Team $name</option>"; } And put your connection information once at the top of the page. Link to comment https://forums.phpfreaks.com/topic/150247-not-have-to-keep-doing-a-query/#findComment-789055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.