Janka no Benzin Tanka Posted May 11, 2010 Report Share Posted May 11, 2010 (edited) Ir datubāze ar vienu tabulu "points" (username, points). Man vajadzīgs mysql_query(), lai izdarītu šādu funkciju: Ja iekšā tabulā jau ir tāds username, tad pieskaita punktus; Ja tabulā nav tāds username, tad ieraksta pa jaunu username un punktus. Palīdziet uztaisīt precīzu kodu. Pagaidām ir šāds, bet nestrādā kā vajag. $run111 = mysql_query("SELECT * FROM `points` WHERE `username` = '$name'"); if (mysql_num_rows($run111) > 0) { mysql_query("UPDATE INTO `points` (`points`) VALUES ('1') WHERE username = '$name'"); } mysql_query("INSERT INTO `points` (`username`, `points`) VALUES ('$name', '1')"); Edited May 11, 2010 by Janka no Benzin Tanka Quote Link to comment Share on other sites More sharing options...
m8t Posted May 11, 2010 Report Share Posted May 11, 2010 http://www.w3schools.com/php/php_mysql_update.asp mysql_query("UPDATE `points` (`points`) VALUES ('1') WHERE username = '$name'"); Quote Link to comment Share on other sites More sharing options...
anonīms Posted May 11, 2010 Report Share Posted May 11, 2010 $eksiste = mysql_result(mysql_query("SELECT count(points) FROM `points` WHERE `username` = '$name'"),0,0); if($eksiste) > 0) { mysql_query("UPDATE points SET points = points+1 WHERE username = '$name'"); } else { mysql_query("INSERT INTO `points` (`username`, `points`) VALUES ('$name', '1')"); } tipa tago? Quote Link to comment Share on other sites More sharing options...
mefisto Posted May 11, 2010 Report Share Posted May 11, 2010 INSERT INTO points( username , points ) VALUES ( 'foobar' , 42 ) ON DUPLICATE KEY UPDATE points = VALUES( points ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.