Raised This Month: $ Target: $400
 0% 

Multiple rows in SQL


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 09-24-2011 , 03:31   Multiple rows in SQL
Reply With Quote #1

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.
reinert is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 09-24-2011 , 05:23   Re: Multiple rows in SQL
Reply With Quote #2

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 
__________________
Impossible is Nothing
Sylwester is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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