Page 1 of 1

Jumping unavailable rows while using a for loop

Posted: Thu Mar 02, 2006 11:33 pm
by cannon_balls
Hi,

i tried searching the forum if this has been mentioned before, but i didnt find any posts so here goes

i have a table containing some information which i constandly edit including deleting some rows without updating them hence creating a break in the incremental continuity of the tables id.

If a particular field is to be displayed on a webpage using a for loop, any ideas how that can be done without getting the errors "unable to jump row .." ?

since i delete rows regularly, my method of using the for loop is to have initially stored the highest id value in a seperate table which will be used for the upper limit of the for loop.

I was also wandering if there was also a better method to get the results done


Regards

Posted: Thu Mar 02, 2006 11:46 pm
by Benjamin
Something like this might help but your question is pretty vague.

Code: Select all

$Query = mysql_query("select `field1`, `field2` from `tablename` where `blah`='blah'",$LinkId);

while ($Data = mysql_fetch_assoc($Query)) {
  echo $Data['field1'];
  echo '<br />';
  echo $Data['field2'];
}

Posted: Thu Mar 02, 2006 11:48 pm
by feyd
I guess I'm not understanding properly; are you saying that you want to display multiple records on a page but don't want to try showing records that have been deleted?

Posted: Fri Mar 03, 2006 12:21 am
by josh
instead of:

Code: Select all

where id >5 and id <10

do

Code: Select all

limit 5,10

Posted: Fri Mar 03, 2006 7:28 pm
by cannon_balls
Thanks guys.

agtlewis's method works perfectly. im gonna go read up on associative arrays now that i have a fir idea what it can do.

Cheers