Wednesday, 21 August 2013

Using MySQL results array more than once

Using MySQL results array more than once

I have the following code in my page
<?php
$dbc = mysql_connect();
$db = mysql_select_db();
$results= mysql_query("SELECT * FROM tbl_teams");
?>
<div class="datagrid"><table>
<thead><tr><th>header</th><th>header</th><th>header</th></tr></thead>
<tbody>
<tr>
<td>
<select name="game1_team1"><option value="0">Choose Team 1</OPTION><?php
while($row = mysql_fetch_array($results)) {echo '<option
value="'.$row['team_ID'].'">'. $row['team_name'].'</option>';}?></select>
</td>
<td>Vs.</td>
<td>
<select name="game1_team2"><option value="0">Choose Team 2</OPTION><?php
while($row = mysql_fetch_array($results)) {echo '<option
value="'.$row['team_ID'].'">'. $row['team_name'].'</option>';}?></select>
</td>
</tr>
The code shows the names of football teams from the MySQL table in
dropdown game1_team1 but not in game1_team2; it's as though I can't use
the same query twice. How do I remedy this? I'd like to use the same
values for 60 identical drop downs on the page.
Can I store the values into an array and resuse them in each dropdown?

No comments:

Post a Comment