SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 30/12/2016, 08:37 PM   #1
Admigo
High-roller
 
Admigo's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 1,840
Reputation: 297
Default Mysql Check if PlayerName and Variable exist

Hello,

I want to detect if a table exist with playername and variable.
Can someone help me out?
I tried this:
Code:
stock ExistPlayerClothes(playerid,pageid)
{
	format(query, sizeof(query), "SELECT * FROM `"#MYSQL_CLOTHES_TABLE2"` WHERE `PlayerName` = '%s' AND `ClothesPageID` = %d", GetName(playerid),pageid);
	mysql_tquery(gSQL, query, "ExistPlayerClothesMYSQL", "i", playerid);
	return 1;
}
But gave me errors:
Code:
[21:50:39] [ERROR] CMySQLQuery::Execute[ExistPlayerClothesMYSQL] - (error #1054) Unknown column 'ClothesPageID' in 'where clause'
[21:50:39] [DEBUG] CMySQLQuery::Execute[ExistPlayerClothesMYSQL] - error will be triggered in OnQueryError

forward ExistPlayerClothesMYSQL(playerid);
public ExistPlayerClothesMYSQL(playerid)
{
	new rows, fields;
    cache_get_data(rows, fields);
	if(!rows)
    {
		//if not exist create new row
		CreatePlayerClothes2Page(playerid);
		return 1;
	}
	return 1;
}
Please help me out.

Admigo.
__________________
Follow me on Instagram @brandonvanommen
Admigo is offline   Reply With Quote
Old 30/12/2016, 08:42 PM   #2
BiosMarcel
Banned
 
Join Date: Jul 2012
Location: Germany
Posts: 1,224
Reputation: 234
Default Re: Mysql Check if PlayerName and Variable exist

I am assuming you didn't mean to check if a table exists, but rather if a column exists. anyways you might just want to do try and error http://wiki.sa-mp.com/wiki/MySQL/R40#mysql_errno

just perform a select statement and see what happens.

You might want to look at this tho:

http://stackoverflow.com/questions/8...ng-select-from
BiosMarcel is offline   Reply With Quote
Old 30/12/2016, 08:44 PM   #3
SoLetsGO
Big Clucker
 
SoLetsGO's Avatar
 
Join Date: May 2016
Location: Germany
Posts: 76
Reputation: 1
Default Re: Mysql Check if PlayerName and Variable exist

Well as the error says the column ClothesPageID is unknown.
Make sure you have created this column with the proper spelling.
SoLetsGO is offline   Reply With Quote
Old 30/12/2016, 08:53 PM   #4
Admigo
High-roller
 
Admigo's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 1,840
Reputation: 297
Default Re: Mysql Check if PlayerName and Variable exist

Quote:
Originally Posted by [Bios]Marcel View Post
I am assuming you didn't mean to check if a table exists, but rather if a column exists. anyways you might just want to do try and error http://wiki.sa-mp.com/wiki/MySQL/R40#mysql_errno

just perform a select statement and see what happens.

You might want to look at this tho:

http://stackoverflow.com/questions/8...ng-select-from
Yes what i am trying to do is detect if those 2 collums are the same as my variable ingame and if not create a new row.
__________________
Follow me on Instagram @brandonvanommen
Admigo is offline   Reply With Quote
Old 30/12/2016, 08:59 PM   #5
BiosMarcel
Banned
 
Join Date: Jul 2012
Location: Germany
Posts: 1,224
Reputation: 234
Default Re: Mysql Check if PlayerName and Variable exist

just assign 'unique' to the columns and you can be sure there wont be any duplicates , just try to create the new row and see if it fails.

But yeah, you should assure that the columns that you use exist.

But besides that, the why you are doing it should work too, the problem is that the column is nonexistant, i hope you understand that
BiosMarcel is offline   Reply With Quote
Old 30/12/2016, 09:39 PM   #6
Admigo
High-roller
 
Admigo's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 1,840
Reputation: 297
Default Re: Mysql Check if PlayerName and Variable exist

If you can see i have 2 tables with ClothesPageID 2 thats why i need this check so it does not duplicate them.
Attached Images
File Type: png MysqldB.png (19.5 KB, 98 views)
__________________
Follow me on Instagram @brandonvanommen
Admigo is offline   Reply With Quote
Old 30/12/2016, 10:09 PM   #7
BiosMarcel
Banned
 
Join Date: Jul 2012
Location: Germany
Posts: 1,224
Reputation: 234
Default Re: Mysql Check if PlayerName and Variable exist

Told you, set the column to unique:

http://www.w3schools.com/sql/sql_unique.asp
BiosMarcel is offline   Reply With Quote
Old 02/01/2017, 08:35 PM   #8
Admigo
High-roller
 
Admigo's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 1,840
Reputation: 297
Default Re: Mysql Check if PlayerName and Variable exist

Quote:
Originally Posted by [Bios]Marcel View Post
Told you, set the column to unique:

http://www.w3schools.com/sql/sql_unique.asp
Thanks mate. Worked like a charm. Rep+. Happy New Year from the neighbours
__________________
Follow me on Instagram @brandonvanommen
Admigo is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help to check if player exist MYSQL ubunttu Scripting Help 12 01/08/2016 12:36 AM
I need help to check if player exist MYSQL ubunttu Server Support 0 30/07/2016 06:24 PM
If PlayerName exist JaKe Elite Scripting Help 15 13/05/2012 06:04 AM
warning 219: local variable "PlayerName" shadows a variable at a preceding level captainjohn Scripting Help 2 13/04/2012 07:44 PM
warning 219: local variable "PlayerName" shadows a variable at a preceding level [DC] Scripting Help 2 02/01/2012 06:29 PM


All times are GMT. The time now is 03:18 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.