Hi.
Im having a script looking something like this:
$sql = "SELECT * FROM Table WHERE columnID='3'";
$var = @mysql_query($sql);
$res = @mysql_fetch_array($var);
$num = @mysql_num_rows($var);
echo "The result from ".$res['name']." returned ".$num." rows<br>";
$counter = 1;
while($resarray = @mysql_fetch_array($var)){
echo "Result ".$counter.": ".$resarray['value']."";
$counter++;
} //end while
First of all I must say that all functions have been tested before I've added the @ to the mysql_xxxx commands.
The problem is that when I run the while-loop it seems to be missing the first result(row) from the query. By this I mean that if $num returned 5 rows, the while loop will only return the last 4 of them.
Anybody know why, and the best workaround for this ?
--> I've tried to run the query again, and that of course works, but is this necessary to make it work(it will "double" the server load doing the query over again) ?
--> This is the "workaround doing a new query:
$counter = 1;
$newvar = mysql_query($var); //doing the query one more time
while($resarray = @mysql_fetch_array($newvar)){ //fetch array from new query result
echo "Result ".$counter.": ".$resarray['value']."";
$counter++;
} //end while
Help would be much appreciated.