I'm trying to determine why mysql_fetch_array does not work on a copied query. In the example below, I try to copy $query to $query2, but when I try to use $query2, it does not come up with anything. Is there some limitation to copying the query and using it again?
I'd like to know how to get this working so I don't have to run the query twice.
I'd like to know how to get this working so I don't have to run the query twice.
Code:
$query = mysql_query(
"SELECT name from employees ORDER BY name");
if (!$query) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}
//copy the query to be used later
$query2=$query;
print ('Employee name:');
print ('<br />');
while ( $row1 = mysql_fetch_array($query) ) {
$name = $row1['name'];
print ($name);
print ('<br />');
}
print ('Employee name in caps:');
print ('<br />');
while ( $row2 = mysql_fetch_array($query2) ) {
$name2 = strtoupper($row2['name']);
print ($name2);
print ('<br />');
}