AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Multiple rows in SQL (https://forums.alliedmods.net/showthread.php?t=168086)

reinert 09-24-2011 03:31

Multiple rows in SQL
 
Hey, why the hell I get multiple rows by the same IP in SQL ? Like I create them when player connects, but I check this:

PHP Code:

format(szTemp,charsmax(szTemp),"SELECT * FROM `players` WHERE (`players`.`player_ip` = '%s')"szIp); 

PHP Code:

if(SQL_NumResults(Query) > 1)
{
/// here I retrieve all information that I need from SQL
}
else
{
//INSERT INTO ...


My table looks like this:

Quote:

player_id INT(6) NOT NULL AUTO_INCREMENT PRIMARY KEY,\
player_ip varchar(32),\
player_name varchar(32),\
...

Where is the problem because every time I enter the server. The new row is created for me, even if there is already a row with that IP.

Sylwester 09-24-2011 05:23

Re: Multiple rows in SQL
 
PHP Code:

player_id INT(6AUTO_INCREMENT PRIMARY KEY,\
player_ip varchar(32UNIQUE KEY,\
player_name varchar(32),\ 

With this you will get sql error if you try to insert same ip more than 1 time. Primary key can not be null, so NOT NULL is not needed.

PHP Code:

if(!SQL_MoreResults(Query))
{
    
//INSERT INTO ...
    
return
}

/// here I retrieve all information that I need from SQL 



All times are GMT -4. The time now is 19:32.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.