Mysql Syntax
#1

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

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

Ok, Anyone else?
Reply
#4

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

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

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

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

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

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 "|".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)