Little bit of SQL help -
iGetty - 22.05.2012
How comes this function loads the data, but not the names correctly?
I have a business named Not Enterable Business and Enterable Business, but it loads this on the console:
Код:
[16:25:09] {FF0000}Business 1
Price $4000
Name: 78
Owner: 78
[16:25:09] {33FF33}Business 2
Price $4000
Name: 69
Owner: 78
[16:25:09] 2 businesses loaded from the MySQL Database.
Here is the function:
pawn Код:
stock LoadBusinesses()
{
new
Str[128],
string[512],
bID,
bName[128],
bOwner[24],
Float:ExtX,
Float:ExtY,
Float:ExtZ,
Float:IntX,
Float:IntY,
Float:IntZ,
Price,
Enterable,
IntID;
mysql_query("SELECT * FROM `Businesses`");
mysql_store_result();
if(mysql_num_rows() > 0)
{
while(mysql_fetch_row(Str))
{
sscanf(Str, "p<|>is[128]s[24]ffffffiii", bID, bName, bOwner, ExtX, ExtY, ExtZ, IntX, IntY, IntZ, IntID, Price, Enterable);
BusinessPickup[bID] = CreatePickup(1272, 1, ExtX, ExtY, ExtZ, 0);
if(Enterable == 0)
{
format(string, sizeof(string), "{FF0000}Business %d\nPrice $%d\nName: %d\nOwner: %d", bID, Price, bName, bOwner);
}
else
{
format(string, sizeof(string), "{33FF33}Business %d\nPrice $%d\nName: %d\nOwner: %d", bID, Price, bName, bOwner);
}
Create3DTextLabel(string, BLUE, ExtX, ExtY, ExtZ, 5.0, 0, 1);
print(string);
bTotal++;
}
}
for(new i = 0; i < MAX_BUSINESS; i++)
{
Business[i][BusinessExteriorX] = ExtX;
Business[i][BusinessExteriorY] = ExtY;
Business[i][BusinessExteriorZ] = ExtZ;
Business[i][BusinessInteriorX] = IntX;
Business[i][BusinessInteriorY] = IntY;
Business[i][BusinessInteriorZ] = IntZ;
Business[i][BusinessInteriorID] = IntID;
Business[i][BusinessPrice] = Price;
Business[i][BusinessEnterable] = Enterable;
format(Business[i][BusinessName], 128, "%s", bName);
format(Business[i][BusinessOwner], 24, "%s", bOwner);
}
mysql_free_result();
printf("%i businesses loaded from the MySQL Database.", bTotal);
}
All help is appreciated!
Re: Little bit of SQL help -
Ruben_Alonso - 22.05.2012
Try this:
pawn Код:
stock LoadBusinesses()
{
new
Str[128],
string[512],
bID,
bName[128],
bOwner[24],
Float:ExtX,
Float:ExtY,
Float:ExtZ,
Float:IntX,
Float:IntY,
Float:IntZ,
Price,
Enterable,
IntID;
mysql_query("SELECT * FROM `Businesses`");
mysql_store_result();
if(mysql_num_rows() > 0)
{
while(mysql_fetch_row(Str))
{
sscanf(Str, "p<|>is[128]s[24]ffffffiii", bID, bName, bOwner, ExtX, ExtY, ExtZ, IntX, IntY, IntZ, IntID, Price, Enterable);
BusinessPickup[bID] = CreatePickup(1272, 1, ExtX, ExtY, ExtZ, 0);
if(Enterable == 0)
{
format(string, sizeof(string), "{FF0000}Business %d\nPrice $%d\nName: %s\nOwner: %s", bID, Price, bName, bOwner);
}
else
{
format(string, sizeof(string), "{33FF33}Business %d\nPrice $%d\nName: %s\nOwner: %s", bID, Price, bName, bOwner);
}
Create3DTextLabel(string, BLUE, ExtX, ExtY, ExtZ, 5.0, 0, 1);
print(string);
bTotal++;
}
}
for(new i = 0; i < MAX_BUSINESS; i++)
{
Business[i][BusinessExteriorX] = ExtX;
Business[i][BusinessExteriorY] = ExtY;
Business[i][BusinessExteriorZ] = ExtZ;
Business[i][BusinessInteriorX] = IntX;
Business[i][BusinessInteriorY] = IntY;
Business[i][BusinessInteriorZ] = IntZ;
Business[i][BusinessInteriorID] = IntID;
Business[i][BusinessPrice] = Price;
Business[i][BusinessEnterable] = Enterable;
format(Business[i][BusinessName], 128, "%s", bName);
format(Business[i][BusinessOwner], 24, "%s", bOwner);
}
mysql_free_result();
printf("%i businesses loaded from the MySQL Database.", bTotal);
}
Re: Little bit of SQL help -
iGetty - 22.05.2012
Worked.
Thanks.
What did you edit to make it work?
Regards, iGetty.
+ rep too.
Re: Little bit of SQL help -
Ruben_Alonso - 22.05.2012
No problem fella!!
I just switched the %d to %s in this lines:
pawn Код:
format(string, sizeof(string), "{FF0000}Business %d\nPrice $%d\nName: %s\nOwner: %s", bID, Price, bName, bOwner);
format(string, sizeof(string), "{33FF33}Business %d\nPrice $%d\nName: %s\nOwner: %s", bID, Price, bName, bOwner);
Re: Little bit of SQL help -
iGetty - 22.05.2012
Wow, I checked them lines :P
Thanks again matey!