SA-MP Forums Archive
Mysql problem - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Mysql problem (/showthread.php?tid=252957)



Mysql problem - Kyle - 03.05.2011

I've tried extracting the data from a table but its not working, its returning the string as null.

There is a table called parkinglot with 10 rows:

parkinglot0
parkinglot1
parkinglot2
parkinglot3
parkinglot4
parkinglot5
parkinglot6
parkinglot7
parkinglot8
parkinglot9


I tried printing the query but its null why? Here is my extracting code: http://pastebin.com/dJQxsiC9


Re: Mysql problem - Georgelopez1 - 03.05.2011

Not sure, but I will look into this.


Re: Mysql problem - Kyle - 04.05.2011

Does anyone else know? This is just weird.


Re: Mysql problem - Calgon - 04.05.2011

First of all, you've created a 256 cell string for no reason. You're selecting everything from that table, you don't need to format a string, you're not formatting a string, you could just directly use
pawn Код:
mysql_query("SELECT * FROM `parkinglot`");
Furthermore, you defined your splitting parameter as '|' yet you're trying to use ',' in sscanf.


Re: Mysql problem - Kyle - 04.05.2011

About the delimiter, (correct me if I'm wrong) When selecting all the fields it basically puts them all together but each new row gets put into a long string but is seperated by the | when that is seperated I then use sscanf to split each of the rows because each row has a field like this:

0.00,0.00,0.00,0,0 (with different information hence me using sscanf to split it using the delimiter ,)


Re: Mysql problem - MadeMan - 04.05.2011

The line looks like this: 0.00|0.00|0.00
So delimiter is '|'

pawn Код:
stock LoadParkingLot()
{
    CheckMySQL();

    mysql_query("SELECT * FROM parkinglot");
    mysql_store_result();

    new field[256];
    new carloop;
    while(mysql_fetch_row_format(field, "|") && carloop < 10)
    {
        unformat(field,"p<|>ffffds[24]",ParkingLotInformation[carloop][CarPositionX],ParkingLotInformation[carloop][CarPositionY],ParkingLotInformation[carloop][CarPositionZ],ParkingLotInformation[carloop][CarPositionA],ParkingLotInformation[carloop][CarModelID],ParkingLotInformation[carloop][CarOwner]);
        if(ParkingLotInformation[carloop][CarModelID] != 0 && ParkingLotInformation[carloop][CarModelID] != -1) { ParkingLotInformation[carloop][VehicleIDD] = CreateVehicle(ParkingLotInformation[carloop][CarModelID], ParkingLotInformation[carloop][CarPositionX],ParkingLotInformation[carloop][CarPositionY],ParkingLotInformation[carloop][CarPositionZ], ParkingLotInformation[carloop][CarPositionA], -1, -1, -1); }
        carloop++;
    }
    return mysql_free_result();
}



Re: Mysql problem - Kyle - 04.05.2011

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
The line looks like this: 0.00|0.00|0.00
So delimiter is '|'

pawn Код:
stock LoadParkingLot()
{
    CheckMySQL();

    mysql_query("SELECT * FROM parkinglot");
    mysql_store_result();

    new field[256];
    new carloop;
    while(mysql_fetch_row_format(field, "|") && carloop < 10)
    {
        unformat(field,"p<|>ffffds[24]",ParkingLotInformation[carloop][CarPositionX],ParkingLotInformation[carloop][CarPositionY],ParkingLotInformation[carloop][CarPositionZ],ParkingLotInformation[carloop][CarPositionA],ParkingLotInformation[carloop][CarModelID],ParkingLotInformation[carloop][CarOwner]);
        if(ParkingLotInformation[carloop][CarModelID] != 0 && ParkingLotInformation[carloop][CarModelID] != -1) { ParkingLotInformation[carloop][VehicleIDD] = CreateVehicle(ParkingLotInformation[carloop][CarModelID], ParkingLotInformation[carloop][CarPositionX],ParkingLotInformation[carloop][CarPositionY],ParkingLotInformation[carloop][CarPositionZ], ParkingLotInformation[carloop][CarPositionA], -1, -1, -1); }
    }
    return mysql_free_result();
}
No, The delimiter in each row is ','.


Re: Mysql problem - MadeMan - 04.05.2011

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
No, The delimiter in each row is ','.
lol you can argue with me or try the code, your choice ..


Re: Mysql problem - Kyle - 04.05.2011

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
lol you can argue with me or try the code, your choice ..
All I'm asking is how can it be because when It saves each row its like with

0.00,0.00,0.00,0,0

Not

0.00|0.00|0.00|0|0


Re: Mysql problem - MadeMan - 04.05.2011

It's because of the mysql_fetch_row_format function.

If you want ',' to be delimiter, then you would use

pawn Код:
mysql_fetch_row_format(field, ",")