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
https://forums.phpfreaks.com/topic/264026-not-displaying-top-row-of-data/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.