开发者

How to check if 1 id is less than another

How can I开发者_C百科 check to see if an item has a lower id than of another item on the same table?

I already have this:

while ($row = $result->fetch_array()) {
if ($row[name] == $myusername) {
    $mysqli->query("DELETE FROM users WHERE name='$myusername' AND password='$mypassword'");
} }

But this is useless as it deletes the account as soon as it's made.


You could add it in the WHERE clause

DELETE FROM users WHERE name='$myusername' AND password='$mypassword' AND users.id < [someOtheID]

You need to give a schema if you want a better answer


Just as you compare the name and password, also compare the id column.

$mysqli->query("DELETE FROM users WHERE name='$myusername' AND password='$mypassword' AND id != $myid");


This assumes you have the user you just added's id (that is an integer) in the variable $id

$mysqli->query("DELETE FROM users 
    WHERE name='$myusername' AND password='$mypassword' AND id != $id"
);

That way you'll delete all users with the same username and password, that wasn't the row you just added.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜