# Php misreporting sql results?

**URL:** https://forum.kirupa.com/t/php-misreporting-sql-results/45796
**Category:** programming
**Created:** [March 18, 2004, 3:49am UTC](https://forum.kirupa.com/t/php-misreporting-sql-results/45796 "2004-03-18T03:49:44Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![El\_Phantom](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@El\_Phantom](https://forum.kirupa.com/u/El_Phantom)
#### Post date: [March 18, 2004, 3:49am UTC](https://forum.kirupa.com/t/php-misreporting-sql-results/45796/1 "2004-03-18T03:49:44Z")

</div>

So, basically, here’s the situation.

I am currently writing a news infobox in flash and php using xml as the data-handler. It basically gets the xml to populate the news items from a database, which is a mySQL db with 3 fields, the primary key, news\_id, is on auto\_increment.

My problem is that sometimes, when i check the news, the most current item will not show up. Sometimes it will be there, and sometimes it won’t, at random. Everything else works great.

I isolated the problem so that I’m sure it has something to do with either this section of the php code or my server. When i test this code with simple echo commands it will sometimes show up with the most current news\_id, and sometimes the previous one.

[AS]

$conn = mysql\_connect($localhost, $login, $password);  
if(!$conn){die(“Authentication Connection error”); }  
mysql\_select\_db($db, $conn) or die(“Cannot connect to database”);  
$query\_id = mysql\_query(“SELECT max(news\_id) AS top\_article FROM news ORDER BY news\_id”);  
while($max\_id\_temp = mysql\_fetch\_array($query\_id)){  
$article\_num = $max\_id\_temp[‘top\_article’];  
$article\_num++;  
$max\_id = $article\_num;  
echo $max\_id . “\<br/\>”;  
}

[/AS]

ARGH!!! Help!!!

It might have something to dow with the way the SELECT max() functions, or heaven knows what else. If you have any experience with this problem and have a suggestion I’d love to hear it, cuz i just can’t figure it out.

Thank you all who respond in advance,

Edit\* oh, and the problem seems to completely disappear after about an hour. What’s that all about? Is it my server caching the query? If so, why does it sometimes display the correct value and sometimes not? CONFUSED. =\*(

–EP
