Mysql Check if PlayerName and Variable exist -
Admigo - 30.12.2016
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.
Re: Mysql Check if PlayerName and Variable exist -
BiosMarcel - 30.12.2016
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
Re: Mysql Check if PlayerName and Variable exist -
SoLetsGO - 30.12.2016
Well as the error says the column ClothesPageID is unknown.
Make sure you have created this column with the proper spelling.
Re: Mysql Check if PlayerName and Variable exist -
Admigo - 30.12.2016
Quote:
Originally Posted by [Bios]Marcel
|
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.
Re: Mysql Check if PlayerName and Variable exist -
BiosMarcel - 30.12.2016
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
Re: Mysql Check if PlayerName and Variable exist -
Admigo - 30.12.2016
If you can see i have 2 tables with ClothesPageID 2 thats why i need this check so it does not duplicate them.
Re: Mysql Check if PlayerName and Variable exist -
BiosMarcel - 30.12.2016
Told you, set the column to unique:
http://www.w3schools.com/sql/sql_unique.asp
Re: Mysql Check if PlayerName and Variable exist -
Admigo - 02.01.2017
Quote:
Originally Posted by [Bios]Marcel
|
Thanks mate. Worked like a charm. Rep+. Happy New Year from the neighbours