scott.stephan Posted June 27, 2009 Share Posted June 27, 2009 Dudes, thank you so much for all your help. I have asked an insane number of dumb/obvious questions and everyone has been 100% helpful. In that spirit, here's another goofy Q: I nab all the results from a table based on a condition. No problem: $query_lots="SELECT * FROM lots_new WHERE lot_sku_id='$curr_key'"; $lots_result=mysql_query($query_lots) or die(mysql_error()); Now, that $lots_result could hold between 1 and maybe 5 rows. To find out, I count: $num_lots=mysql_num_rows($lots_result); Okay, so 1,2,3 rows, whatever. Here's the problem- These results are displayed in a table. IF there's just one record, then we display those results at the END of the first row of the table: Item ItemDesc Lot LotQTY Wh Desc 5 15 However, if there are TWO or MORE results, we need to create a new row for them: Item ItemDesc Lot LotQTY Wh Desc 5 15 6 10 ' So, I wrote some code: while($lots_row=mysql_fetch_array($lots_result)){ echo "<td class='boltd'>$lots_row[lot] </td> <td class='boltd'>$lots_row[lot_qty] $bol_row[sau]</td> </tr>"; if($num_lots > 1){ echo "<tr class'hint'><td class='boltd'> </td> <td class='boltd'> </td> <td class='boltd'>$lots_row[lot] </td> <td class='boltd'>$lots_row[lot_qty] $bol_row[sau] </td> </tr>"; } } And I'm sure you can see the problem. If there's just ONE ROW, we're okay! We finish up the row and go home. If there is more than one, we have a problem- It outputs every row. So, basically what I need to do is say if($num_lots>1){ for( $c=1; c < $num_lots; c==){ START FROM THE C ROW of $LOTS_RESULT!!! } START FROM THE SECOND RESULT } How can I tell $lots_result, the result of the SQL query, to start from the x row of it's retrieved results and not to spill it's guts everytime? Do I need to use a different call, like fetch_array()? Thanks, I hope that wasn't too confusing. Quote Link to comment https://forums.phpfreaks.com/topic/163923-how-to-skip-a-row-inside-of-a-result/ Share on other sites More sharing options...
scott.stephan Posted June 27, 2009 Author Share Posted June 27, 2009 I guess a simpler question is: How can I tell the result of mysql_fetch_array , to start from the second row it fetches? Quote Link to comment https://forums.phpfreaks.com/topic/163923-how-to-skip-a-row-inside-of-a-result/#findComment-864856 Share on other sites More sharing options...
scott.stephan Posted June 27, 2009 Author Share Posted June 27, 2009 I feel like this has to be simple, but I can't seem to find anyone else who has ever had this problem. Hmm. Quote Link to comment https://forums.phpfreaks.com/topic/163923-how-to-skip-a-row-inside-of-a-result/#findComment-864862 Share on other sites More sharing options...
scott.stephan Posted June 28, 2009 Author Share Posted June 28, 2009 I ended up using this, suggested over at AskMetafilter: $lots_result = ... $first_row_values = mysql_fetch_array($lots_result)) while ($row = mysql_fetch_array($lots_result)) { ... 2onwards} So it rips off the first result, I always display that one and if there are others remaining we deal with them Quote Link to comment https://forums.phpfreaks.com/topic/163923-how-to-skip-a-row-inside-of-a-result/#findComment-864884 Share on other sites More sharing options...
Ken2k7 Posted June 28, 2009 Share Posted June 28, 2009 After the if statement do another call to mysql_fetch_array, so $row = mysql_fetch_array($lots_result) after the if ($num_lots > 1) statement. Don't misread and put that inside the if statement. Put it AFTER the entire if statement. Quote Link to comment https://forums.phpfreaks.com/topic/163923-how-to-skip-a-row-inside-of-a-result/#findComment-864920 Share on other sites More sharing options...
sasa Posted June 28, 2009 Share Posted June 28, 2009 try $x = ''; while($lots_row=mysql_fetch_array($lots_result)){ echo $x, "<td class='boltd'>$lots_row[lot] </td> <td class='boltd'>$lots_row[lot_qty] $bol_row[sau]</td></tr>"; $x = "<tr class'hint'><td class='boltd'> </td> <td class='boltd'> </td> "; } Quote Link to comment https://forums.phpfreaks.com/topic/163923-how-to-skip-a-row-inside-of-a-result/#findComment-864999 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.