BlakPhoenix Posted June 12, 2012 Share Posted June 12, 2012 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. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 12, 2012 Share Posted June 12, 2012 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. Quote Link to comment Share on other sites More sharing options...
BlakPhoenix Posted June 12, 2012 Author Share Posted June 12, 2012 THANK YOU!!! I knew it would be something terribly embarrassing I was overlooking! You just made my day! Quote Link to comment 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.