RE: [PHP] counting number of records in a MySQL table; how do I get

From: Date: Thu, 03 Oct 2002 13:16:16 +0000
Subject: RE: [PHP] counting number of records in a MySQL table; how do I get
Groups: php.general 
Request: Send a blank email to php-general+get-118733@lists.php.net to get a copy of this message
An alternative way is to add a primary or unique key and make the code snippet like this: mysql_query("INSERT ignore into AuthNum (FirstNum, LastNum, NextNum, KeyField) VALUES (1,2,3,1)",$dblink); mysql_query("Update AuthNum Set FirstNum = 1, LastNum = 2, NextNum = 3",$dbLink); If there is a record already the insert won't work because it will have the same value in the key field. The update query is unchanged and there is no counting of records. I get the impression it's just a 1-record table. > I need to do either an insert or update into a MySQL table. Insert if there > are 0 records or update if one record exist: > > This is my code snippet: > > if (mysql_query("SELECT COUNT(*) FROM AuthNum") == 0) { > mysql_query("INSERT into AuthNum (FirstNum, LastNum, NextNum) VALUES > (1,2,3)",$dblink); > } else { > mysql_query("Update AuthNum Set FirstNum = 1, LastNum = 2, NextNum = > 3",$dbLink); > } > > My problem is, a record never gets inserted because the SELECT COUNT query > is returning a resource ID of 2. How can I get the actual number of records > in the table? ____________________________________________________________ Tired of all the SPAM in your inbox? Switch to LYCOS MAIL PLUS http://www.mail.lycos.com/brandPage.shtml?pageId=plus

« previous php.general (#118733) next »