Jump to content

MySQL array problem


c_pattle

Recommended Posts

I have an array of data from a mysql result.  The problem I have is that I want to find out what the next row is going to be in advanced.  At the moment I have

 

while($row = mysql_fetch_assoc($rs) {

    echo 'Order ID: ' . $row['order_id'];

}

 

This just echo's out the order_id of the current row.  However I want to find out if the order_id on the next row is going to be the same or different.  If it's different I will want to echo out something else.

 

while($row = mysql_fetch_assoc($rs) {

    echo 'Order ID: ' . $row['order_id'];

    //If order_id + 1 is different then echo
   echo 'Total: ' . $row['total']

}

 

Does anyone know a way round this problem?

 

Thanks

Link to comment
Share on other sites

<?php

$test = "";

while($row = mysql_fetch_assoc($rs) {
    echo 'Order ID: ' . $row['order_id'];

    if($row['order_id'] == $test){
         echo 'Total: ' . $row['total'];
    }
    $test = $row['order_id'];
}

?>

Link to comment
Share on other sites

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.