PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
saltriver
Forum Commoner
Posts: 59 Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT
Post
by saltriver » Thu Apr 20, 2006 11:28 pm
if (!$num_rows) {
That's the little bugger.
So here it is in it's final form:
Code: Select all
$recordID = $_GET['recordID'];
$db = mysql_select_db($db_name, $db_handle) or die (mysql_error());
$rc = "select * from popup where rest = '$recordID'";
$restchk = mysql_query($rc) or die (mysql_error());
$num_rows = mysql_num_rows($restchk);
if (!$num_rows) {
$sql = "insert into popup values ('', '$recordID', now(), '1')";
mysql_query($sql);
} else {
$sqlu = "update popup set hits = hits ++1 where rest = '$recordID'";
mysql_query($sqlu);
};
Muchos Gacias, ole!
Ollie Saunders
DevNet Master
Posts: 3179 Joined: Tue May 24, 2005 6:01 pm
Location: UK
Post
by Ollie Saunders » Fri Apr 21, 2006 2:30 pm
my code relies on the id being an integer, and it should be for performance reasons. using a string as the id is sloooow
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Fri Apr 21, 2006 5:54 pm
I've never said anything about using (VAR)CHAR / STRING as datatype... Btw, with the query i suggested you only have one query.. Which is more performant than two
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri Apr 21, 2006 6:09 pm
So many cool little tricks and tips I've learned from you timv... keep em coming.
Ollie Saunders
DevNet Master
Posts: 3179 Joined: Tue May 24, 2005 6:01 pm
Location: UK
Post
by Ollie Saunders » Mon Apr 24, 2006 3:41 am
Code: Select all
INSERT INTO foo VALUES (bar)
ON DUPLICATE KEY UPDATE countcol = countcol + 1
oh wow that's very cool