scott.stephan Posted June 19, 2009 Share Posted June 19, 2009 I'm in a situation where IF $row[whatever] == x , then I need it to skip the next five rows. Using the traditional $query="SELECT * FROM whatever"; $result=mysql_query($query) or die(mysql_error()); while($row=mysql_fetch_array($result)){ blahblahblah } How can I tell it "SKIP THIS ROW!" or "Skip X Rows". I can't do row++, that doesn't quite make sense. I don't think there's a numeric, like, "Well, this is row 1 of 20" and I can say, "Well, go to Row 6, if Row 1 is whatever". Link to comment https://forums.phpfreaks.com/topic/162964-skipping-a-row-via-whilerow/ Share on other sites More sharing options...
scott.stephan Posted June 19, 2009 Author Share Posted June 19, 2009 $row[] returns an array of SQL results, right? If a record has 10 fields, $row[1] is record 1, field 1, but $row[11] is record 2, field 1. So could I $row[current+10]? Link to comment https://forums.phpfreaks.com/topic/162964-skipping-a-row-via-whilerow/#findComment-859855 Share on other sites More sharing options...
xphoid Posted June 19, 2009 Share Posted June 19, 2009 To skip a single row you can use continue. quick example: while($row=mysql_fetch_array($result)) { if($row['whatever']==1) { continue; } // non-skipped code } To skip X amount of rows you could build an array and then loop through the keys numerically. $array = array(); while($row=mysql_fetch_array($result)) { $array[] = $row; } for($i=0; $i<count($array); $i++) { $row = $array[$i]; if($row['whatever'] == 1) { // skip this row plus 5 more $i += 5; continue; } // non-skipped code } Link to comment https://forums.phpfreaks.com/topic/162964-skipping-a-row-via-whilerow/#findComment-859903 Share on other sites More sharing options...
Ken2k7 Posted June 20, 2009 Share Posted June 20, 2009 Why do I get the feeling that this is just bad design? Link to comment https://forums.phpfreaks.com/topic/162964-skipping-a-row-via-whilerow/#findComment-860017 Share on other sites More sharing options...
scott.stephan Posted June 22, 2009 Author Share Posted June 22, 2009 Why do I get the feeling that this is just bad design? Ha. Because it is There are an enormous number of weird irregularities with the data coming in, coupled with changing demands on both ends of the sending/recieveing spectrum means that this program is a lot of cobbled together little solutions meant to meet a deadline more than to be incredibly elegant. Once things are settled into place there'll have to be a long sort of reconciliation period. Keyword right now is 'working' not 'charming'. Anyway, thanks for the tips! I'll play a bit and see what comes up. Link to comment https://forums.phpfreaks.com/topic/162964-skipping-a-row-via-whilerow/#findComment-861239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.