What I am trying to do is query a database using a loop conditional
and return the data but my code only repeats the first instance multiple times!
My code is below, I have tried to use comments to explain what should be happeing!
[php]$rows = null;
$q1 = “SELECT * FROM table”;
$r1 = mysql_query($q1) or die(mysql_error());
$i = 1;
while($i <= 5){
$start = (1000 * $i);
$end = ($start + 1000);
while($a1 = mysql_fetch_array($r1, MYSQL_ASSOC)){
/* query the database where ‘start’ is >= 1000 and where ‘end’ is <= 2000,
this should loop so the next time is where ‘start’ >= 1000 * $i should be 1000 then 2000, 3000 etc…
and where ‘end’ should be 2000, 3000, 4000 etc…
*/
if($a1[‘start’] >= $start && $a1[‘end’] <= $end){
$rows .= $a1[‘col1’].’:’.$a1[‘col2’]."\n";
}
}
echo nl2br(trim($rows.’
’));
$i++;
}
/* The problem is that it always shows multiple instances of the first result only
where start = 1000 and end = 2000
*/
[/php]
Any help would be much appreciated!!