Re: Check data exists in MySQL

From: Date: Thu, 21 Nov 2002 05:35:42 +0000
Subject: Re: Check data exists in MySQL
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-23550@lists.php.net to get a copy of this message
$sql="SELECT num FROM count where dept='$dept' AND deptsub='$deptsub'"; -------------------- begin of replace ------------------------------ $result = mysql_query($sql,$db); $page_count = mysql_num_rows($result); # If does not exist in the database, insert a new entry if (!$page_count){ ---------------------- end of replace ------------------------ $sql = "INSERT INTO count VALUES('$dept', '$deptsub', '0'); $result = mysql_query($sql,$db); } #Update the count in the database $page_count = $page_count + 1; $sql="UPDATE count SET num='$page_count' WHERE dept='$dept' AND deptsub='$deptsub'"; $result = mysql_query($sql, $db);

« previous php.db (#23550) next »