note 46704 deleted from ref.mysql by tomsommer

From: Date: Wed, 20 Oct 2004 22:33:13 +0000
Subject: note 46704 deleted from ref.mysql by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-78859@lists.php.net to get a copy of this message
Note Submitter: php at 3wheel dot net ---- Re: Melvin Nava The first select query is not needed. You can use mysql_affected_rows() to see if the update modified any rows. Also, it is a waste to fetch a value and do the addition in PHP when you can do it in the database (much safer). If no rows were affected, the insert is necessary: <? $c_update = "UPDATE stats_pagecounter SET page_hits = page_hits + 1 WHERE page_name = '$page'"; $c_hit = mysql_query($c_update, $c_link) or die('counter UPDATE error: '.mysql_errno().', '.mysql_error()); if (mysql_affected_rows($c_link) == 0) { //not found $c_insert = "INSERT INTO stats_pagecounter VALUES ( '0', '$page', '1')"; $c_page = mysql_query($c_insert, $c_link) or die('counter INSERT error: '.mysql_errno().', '.mysql_error()); $pcounter = 1; } ?>

« previous php.notes (#78859) next »