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

Link to comment
Share on other sites

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