PDA

View Full Version : Number rows help (MySQL)


Kraeror
07/01/2018, 02:29 PM
I have one realy big problem! I can't find the number of rows, because I want to create one more row (a house)! Firstly when I start the server I can create one house and it is saving perfect, but when I try to create one more I have to restart the server again, because when I'm trying to create second house, it is not saving! The problem is because the rows are counted only one time (but in the script I'm counting them always when I want to create the ouse)
Here is my creating house command: (I'm testing the number, when I have created one house it works correct, but when I'm trying to create another one it doesn't counts) Please help me guys!)
mysql_tquery(zMySQL, "SELECT * FROM `houses` ORDER BY `ID` ASC");
new h = cache_num_rows()+1;
printf("%d", h);

Zeth
07/01/2018, 02:41 PM
try
cache_get_row_count(destination);

and whenever you are creating a new house, try to make a variable which will be AUTO_INCREMENT in the mysql table, so that you dont need to count rows whenever you are creating a new house.

Kraeror
07/01/2018, 03:00 PM
Still the problem with this couting, whenever I restart the server I can create only one house, that is saving! And yes I'm saving the house inside the command!

Kraeror
07/01/2018, 04:43 PM
Any ideas?

aoEXE
07/01/2018, 05:16 PM
mysql_query(zMySQL, "SELECT * FROM `houses` ORDER BY `ID` ASC",true);
new h = cache_num_rows()+1;
printf("%d", h);

However, the correct way to do this is to create an AUTO_INCREMENT field or you will have ID problems.

Kraeror
07/01/2018, 05:28 PM
WOWWW HOW YOU FIXED IT?? GOOD JOB!!!!!!
Thanks a lot +1 REP!
And can you tell me what is AUTO_INCREAMENT?

Lucases
07/01/2018, 07:06 PM
WOWWW HOW YOU FIXED IT?? GOOD JOB!!!!!!
Thanks a lot +1 REP!
And can you tell me what is AUTO_INCREAMENT?

Basically, it's an unique id that keeps increasing when you add a row. Even if you delete some rows it will always increase, that's why it's unique