Reply to Re: Glitch in php or count() in mysql?

Your name:

Reply:


Posted by Jerry Stuckle on 10/22/05 18:46

Schraalhans Keukenmeester wrote:
> X-Followup: comp.lang.php
>
> I have a PHP script that adds messages to a simple MySQL Database.
> (PHP 5.0.3, MySQL 4.1.1)
>
> One of the fields it stores is msgid.
> The new msgid is a count of all current msgs in the db plus one
>
> $query = 'select count(*) from messagesdb;';
> $result = mysql_query ($query, $conn);
> $msgid = mysql_result ($result, 'count(*)') + 1;
>
> The next message is added using the above msgid.
> For some reason (there are NO other scripts/systems accessing this
> table, it is all on a local testmachine) I now have about 200 messages
> in the system, but some id's occur more than once, up to 4 times.
>
> I cannot explain this behaviour. I know I could avoid the entire issue
> by autonumbering the messages, but still there is something funny going on.
>
> I am wondering, is php messing up, or is this a mysql glitch, or am I
> missing something here ?
>
> Thanks for your time
> Sh

In addition to what the others have said, if you ever delete a message
from the table, COUNT(*) will be decremented and you'll have duplicate
values.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация