sqlite read issue - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: sqlite read issue (
/showthread.php?tid=325743)
sqlite read issue -
boelie - 14.03.2012
Hello,
I am trying to read from my database here. As you can see i tried many things XD (if you look at the // )
pawn Код:
ReadVehicle(playerid);
public ReadVehicle(playerid)
{
new query[256],string[128];
new DBResult:qresult;
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
//SELECT vehicleinfo FROM vehicleinfo WHERE username = '%s' AND slotid = %d", pname, slotid);
//format(string,sizeof(string),"SELECT Level FROM `users` WHERE Username = '%s'", PlayerName[playerid]);
//format(query,sizeof(query),"SELECT stat FROM `Users` WHERE `Name`= '%s'",pName);
//format(query,sizeof(query),"SELECT Name FROM `Users` WHERE `Name`= '%s'",pName);
//format(query, sizeof(query), "SELECT Users FROM Users WHERE name = '%s'",pName);
format(query, sizeof(query), "SELECT Users FROM `Users` WHERE name = '%s'",pName);
qresult = db_query(testdb,string);
//if(db_num_rows(qresult) == 1)
// {
db_get_field_assoc(qresult,"name",string,6);
format(string,sizeof(string),"%s",strval(string));
SendClientMessage(playerid,0xAFAFAFAA,string);
//}
db_free_result(qresult);
}
I'm very confused now and i need help, i just want it to read the name out of the database and sends a clientmessage to confirm that it did. All it does now is sending an empty string
Thanks in advance
Re : sqlite read issue -
Cyril59 - 14.03.2012
Try this:
pawn Код:
ReadVehicle(playerid);
public ReadVehicle(playerid)
{
new query[256],string[128];
new DBResult:qresult;
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
//SELECT vehicleinfo FROM vehicleinfo WHERE username = '%s' AND slotid = %d", pname, slotid);
//format(string,sizeof(string),"SELECT Level FROM `users` WHERE Username = '%s'", PlayerName[playerid]);
//format(query,sizeof(query),"SELECT stat FROM `Users` WHERE `Name`= '%s'",pName);
//format(query,sizeof(query),"SELECT Name FROM `Users` WHERE `Name`= '%s'",pName);
//format(query, sizeof(query), "SELECT Users FROM Users WHERE name = '%s'",pName);
format(query, sizeof(query), "SELECT Users FROM `Users` WHERE name = '%s'",pName);
qresult = db_query(testdb,query);
//if(db_num_rows(qresult) == 1)
// {
db_get_field_assoc(qresult,"name",string,6);
format(string,sizeof(string),"%s",strval(string));
SendClientMessage(playerid,0xAFAFAFAA,string);
//}
db_free_result(qresult);
}
Re: sqlite read issue -
boelie - 14.03.2012
Same result, ingame i see an empty message maybe its just something wrong with the string but i just dont see it.
Edit: its not the string thats wrong it just doesnt do anything between this;
pawn Код:
if(db_num_rows(qresult) == 1) //
{
db_get_field_assoc(qresult,"name",string,6);
format(string,sizeof(string),"%s",strval(string));
SendClientMessage(playerid,0xAFAFAFAA,string);
}
So my guess is i mixed up something else with the database part select from where :S
Re: sqlite read issue -
boelie - 16.03.2012
Still cant make it read the database any help please ?