PDA

View Full Version : [Question] MySQL Loading multi rows


tony_fitto
23/11/2012, 10:02 PM
Hey guys,

I've been trying a while to load keys from a database by this line here
"SELECT * FROM `vehicles` WHERE cOwner='%s' ORDER BY cID ASC" but some how when I tried it before I just got the first row it found on all 5 keys, now I'm back from scratch since I dont have the code anymore removed it

I just wonder are there anyone here that know how to load multi rows from a database on different keys, so when it has loaded key 300 it ignores key 300 when loading key number 2?

Best Regards
Tony

ikey07
24/11/2012, 12:01 AM
add LIMIT 1 at the end of query,or thats not the case?

You have to store them all somewhere and I really didnt get why you want it ignores something, just select by cID then.

tony_fitto
24/11/2012, 01:40 PM
You see thats what I'm trying to do,

I have 5 sets of keys, 3 are for normal players and 2 more are for premium.
Now when a player logs in cID = vehicleid. It updates every time the server restarts.
so I need to put the vehicle id which is cID in the DB to load on player login in hte server,

This is what I made so far.
new vString[900], vString2[900], idx = 0;
format(vString, sizeof(vString), "SELECT * FROM `vehicles` WHERE cOwner='%s' ORDER BY cID ASC", EscapedName);
mysql_query(vString2);
mysql_store_result();
new rows = mysql_num_rows();
mysql_free_result();

if(mysql_retrieve_row()) //data was retrieved
{
while (idx < rows)
{
if(idx == 0)
{
mysql_get_field("cID", vString);
PlayerInfo[playerid][pPcarkey] = strval(vString);
idx++;
}
else if(idx == 1)
{
mysql_get_field("cID", vString);
PlayerInfo[playerid][pPcarkey2] = strval(vString);
idx++;
}
else if(idx == 2)
{
mysql_get_field("cID", vString);
PlayerInfo[playerid][pPcarkey3] = strval(vString);
idx++;
}
else if(idx == 3)
{
mysql_get_field("cID", vString);
PlayerInfo[playerid][pPcarkey4] = strval(vString);
idx++;
}
else if(idx == 4)
{
mysql_get_field("cID", vString);
PlayerInfo[playerid][pPcarkey5] = strval(vString);
idx++;
}
}
mysql_free_result();
}

But it only gives me the first vehicles id in the database on all my keys. Since I allready have 5 cars, but still I get the first cID on all keys, so it doesn't read the rest vehicles from the DB.

EDIT: Didn't get it to work, re-wrote the entire system and got the keys to load correctly.