Jump to content

Not have to keep doing a query?


SEVIZ

Recommended Posts

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.