SA-MP Forums Archive
Mysql Syntax - 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 Syntax (/showthread.php?tid=188755)



Mysql Syntax - Kyle - 08.11.2010

I have the following:

pawn Код:
CheckMySQL();
new string[500];

 format(string, 500, "INSERT INTO `houses` (`HouseIntCoordsX`, `HouseIntCoordsY`, `HouseIntCoordsZ`, `Interior`, `Vworld`) VALUES ('%f', '%f', '%f', '%d', '%d') WHERE `House-IDD` = '%d' ", HouseIntCoordsX1,HouseIntCoordsY1,HouseIntCoordsZ1,Interior1,VirtualWorld1,HouseID);

mysql_query(string);

MySQL server version for the right syntax to use near 'WHERE `House-IDD` = '0'' at line 1)
How to fix? Also How to stop a loop from running if the row is empty or not excistant.


Re: Mysql Syntax - DarrenReeder - 08.11.2010

Use

pawn Код:
sizeof(string)
instead of "500" on the second parameter. This is how you should format strings to avoid problems... Not too sure about your problem though, sorry mate.


Re: Mysql Syntax - Kyle - 09.11.2010

Ok, Anyone else?


Re: Mysql Syntax - Rachael - 09.11.2010

Try changing the hyphen to an underscore, I don't think you can use hyphens in column names.
(thanks Doefler)

You need to store the result.
mysql_fetch will return 0 if there are no more rows in the result.
so use
pawn Код:
mysql_store_result(connection);
while(mysql_fetch_row_format(,variable," ",connection))
{
     //process data ( try sscanf )
}
mysql_free_result(connection);



Re: Mysql Syntax - iJumbo - 09.11.2010

try to not the use the space WHERE `House-IDD` = '%d'< here is one space ...


Re: Mysql Syntax - Cameltoe - 09.11.2010

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
I have the following:

pawn Код:
CheckMySQL();
new string[500];

 format(string, 500, "INSERT INTO `houses` (`HouseIntCoordsX`, `HouseIntCoordsY`, `HouseIntCoordsZ`, `Interior`, `Vworld`) VALUES ('%f', '%f', '%f', '%d', '%d') WHERE `House-IDD` = '%d' ", HouseIntCoordsX1,HouseIntCoordsY1,HouseIntCoordsZ1,Interior1,VirtualWorld1,HouseID);

mysql_query(string);

MySQL server version for the right syntax to use near 'WHERE `House-IDD` = '0'' at line 1)
How to fix? Also How to stop a loop from running if the row is empty or not excistant.
What are you trying to achieve?


Re: Mysql Syntax - Bumbis - 09.11.2010

Do you want to Insert a row into another row?

If you want to change a row, use UPDATE.

pawn Код:
"UPDATE `tablename` SET `field`='value' WHERE `Something`='value'"



Re: Mysql Syntax - LarzI - 09.11.2010

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
... Also How to stop a loop from running if the row is empty or not excistant.

Loop, as in for loop?

If so - put "break;" without the " " 's


Re: Mysql Syntax - Cameltoe - 09.11.2010

Quote:
Originally Posted by LarzI
Посмотреть сообщение
Loop, as in for loop?

If so - put "break;" without the " " 's
This will keep looping through the rows until mysql_fetch_row returns 0.
pawn Код:
while(mysql_fetch_row(QueryString,Delim)) // Change QueryString to the string you queried, and Delim to how ever you want to split the string.. i prefer "|".