mysql "num_rows" problem...
#1

well...
I made my own house system for my server...
however as there were a few wrongly saved houses, which I deleted the "auto increment" got f*cked up and it saved them as id 49, 50, 53, 54, etc...
and I couldn't add a 51 and 52... just could change the IDs later, however then I can also manually add them to the list if I have to check it again and again..
so to the current story:
I've disabled the auto increment and am using this code now:
pawn Код:
format(query, sizeof(query), "SELECT * FROM `Houses`");
mysql_query(query);
mysql_store_result();
new row = mysql_num_rows();
mysql_free_result();
format(query, sizeof(query), "INSERT INTO `Houses` (`id`, `Price`, `x`, `y`, `z`) VALUES ('%d', '%f', '%f', '%f')",row, price, x, y, z);
mysql_query(query);
I'm using stricken's plugin (the first ID is '0', so - to my knowledge - I can use 'row' as the ID)...
the mysql log says this:
pawn Код:
Error (0): Failed to exeute query. Column count doesn't match value count at row 1.
any idea what's wrong?
Reply
#2

EDIT: Actually, scrap that. What is it that you are actually trying to do? Can you explain a little more?
Reply
#3

fixed

pawn Код:
format(query, sizeof(query), "INSERT INTO `Houses` (`id`, `Price`, `x`, `y`, `z`) VALUES (%d, %d, %f, %f, %f)",row, price, x, y, z);
mysql_query(query);
Reply
#4

Quote:
Originally Posted by Donya
Посмотреть сообщение
fixed

pawn Код:
format(query, sizeof(query), "INSERT INTO `Houses` (`id`, `Price`, `x`, `y`, `z`) VALUES (%d, %d, %f, %f, %f)",row, price, x, y, z);
mysql_query(query);
That's exactly what I put, I just didn't understand the goal.
Reply
#5

oh lol you're right (donya) didn't notice I forgot the value...
anyway lewwy your code returned the error that mysql_num_rows() was called when no querry was stored or so..
so finally I got to this:
pawn Код:
format(query, sizeof(query), "SELECT * FROM `Houses`");
mysql_query(query);
mysql_store_result();
format(query, sizeof(query), "INSERT INTO `Houses` (`id`, `Price`, `x`, `y`, `z`) VALUES (%d, %d, '%f', '%f', '%f')", (mysql_num_rows() + 1), price, x, y, z);
mysql_free_result();
mysql_query(query);
which works well
Reply
#6

Ah so my code was right before I edited it, then when I edited it again I forgot the + 1.
I just didn't understand what you were trying to do, my apologies!
Reply
#7

np :P finally helped me to get it working
so thanks to you 2
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)