Mysql Check if PlayerName and Variable exist
#1

Hello,

I want to detect if a table exist with playername and variable.
Can someone help me out?
I tried this:
Код:
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:
Код:
[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.
Reply
#2

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 https://sampwiki.blast.hk/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
Reply
#3

Well as the error says the column ClothesPageID is unknown.
Make sure you have created this column with the proper spelling.
Reply
#4

Quote:
Originally Posted by [Bios]Marcel
Посмотреть сообщение
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 https://sampwiki.blast.hk/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.
Reply
#5

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
Reply
#6

If you can see i have 2 tables with ClothesPageID 2 thats why i need this check so it does not duplicate them.
Reply
#7

Told you, set the column to unique:

http://www.w3schools.com/sql/sql_unique.asp
Reply
#8

Quote:
Originally Posted by [Bios]Marcel
Посмотреть сообщение
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)