Jump to content

Not displaying top row of data


BlakPhoenix

Recommended Posts

Hey all,

 

So I'm quite new to php and mySQL and have been working on pushing my knowledge on both subjects. I've got my queries running how i want for the most part however for some reason I am struggling to display the most recent row in the tables, here is a sample of the ode that grabs and displays the DB:

 

<?php

// Grab data from database

$buyQuery = "SELECT * FROM char_$charID WHERE transactionType = 'buy' ORDER BY unixTime DESC";

$buyResult = mysql_query($buyQuery) or die(mysql_error());

 

 

$buyRow = mysql_fetch_array($buyResult);

?>

 

<div class="left">

<table border='0'>

<tr> <th>When</th> <th>Item</th> <th>Quantity</th> <th>Price</th> </tr>

 

<?php

while($buyRow = mysql_fetch_array($buyResult)){

//formatting

$price = $buyRow['price'];

$formatPrice = number_format($price, 0, '.', ',');

$quantity = $buyRow['quantity'];

$formatQuantity = number_format($quantity, 0, '.', ',');

$unixGmtTime = ($buyRow['unixTime'])+28800;

$totalBuy = $totalBuy + $price;

 

// display the data

echo "<tr><td>";

echo time_elapsed_string($unixGmtTime)." ago";

echo "</td><td>";

echo $buyRow['typeName'];

echo "</td><td>";

echo $formatQuantity;

echo "</td><td class='loss'>";

echo $formatPrice;

echo "</td></tr>";

}

?>

</table>

</div>

 

This displays data like the attached image, however this is missing the most recent item that has "buy" in the transactionType column. When the DB gets updated, it always misses the newest row. This page is included in a parent page which connects to the db, etc.

 

What am I doing wrong? Please let me know if you need further data/images/code.

post-134556-13482403588293_thumb.png

Link to comment
Share on other sites

You discard the first result by calling mysql_fetch_array()

 

<?php
// Grab data from database
$buyQuery = "SELECT * FROM char_$charID WHERE transactionType = 'buy' ORDER BY unixTime DESC";
$buyResult = mysql_query($buyQuery) or die(mysql_error());


$buyRow = mysql_fetch_array($buyResult); // <---- HERE
?>

 

Each call to mysql_fetch_array() moves the internal data pointer to the next record.

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.