Jump to content
php.lv forumi

mysql_query


Recommended Posts

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 by Janka no Benzin Tanka
Link to comment
Share on other sites

$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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...