Jumping unavailable rows while using a for loop

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
cannon_balls
Forum Newbie
Posts: 10
Joined: Tue Jan 24, 2006 2:23 pm

Jumping unavailable rows while using a for loop

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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'];
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

instead of:

Code: Select all

where id >5 and id <10

do

Code: Select all

limit 5,10
cannon_balls
Forum Newbie
Posts: 10
Joined: Tue Jan 24, 2006 2:23 pm

Post 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
Post Reply