Mysql problem
#1

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

Not sure, but I will look into this.
Reply
#3

Does anyone else know? This is just weird.
Reply
#4

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.
Reply
#5

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

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();
}
Reply
#7

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 ','.
Reply
#8

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

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

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, ",")
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)