phpbar.de logo

Mailinglisten-Archive

[php] Nochmal INSERT/REPLACE

[php] Nochmal INSERT/REPLACE

Reiner Kukulies reiner.kukulies_(at)_uni-koeln.de
Wed, 16 Jun 1999 20:32:18 +0100


Am 16 Jun 99, schrieb Kronsbein, Mark zu "[php] Nochmal INSERT/REPLACE":

> [schnipp]
> $query = mysql_fetch_row(mysql_query("select * from $userstable where(url
> = '$url')")); if ($query == false){ $hits = "1"; $query2 = "INSERT INTO
> $userstable (url,hits) VALUES('$url','$hits')"; } else { $hitquery =
> "select hits from $userstable where(url = '$url')"; $hits2 =
> mysql_query($hitquery);
> $hits = $hits2 + 1;
> $query2 = "replace into $userstable (hits) VALUES('$hits') where (url =
> '$url')"; } MYSQL_QUERY($query2); [schnapp]

Das sollte auch einfacher gehen (ungetestet):

if (!mysql_query("insert into $userstable (url,hits) values 
('$url',0)")) {
  mysql_query("update $userstable set hits=hits+1 where url='$url'");
}

Gruß, Reiner

-- 
NETZKONZEPTE - http://kukulies.de


php::bar PHP Wiki   -   Listenarchive