Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/163923-how-to-skip-a-row-inside-of-a-result/
Share on other sites

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

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> ";
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.