Help me, please! Why my code always return 0 :( | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Help me, please! Why my code always return 0 :(

PHP //wait for other page insert data to database about 40s and $timeout set to 5s $num_row = array(); $sleeping_time = 0; while ($sleeping_time < $timeout && $num_row['total'] < $count_keyword) { sleep(2); $sleeping_time += 2; $query = "SELECT count(*) as total FROM table"; $result = mysql_query($query)or die(mysql_error()); $num_row = mysql_fetch_array($result); } echo $sleeping_time;

13th Sep 2017, 8:21 AM
Lương Văn Của
Lương Văn Của - avatar
3 Answers
+ 4
From the code that is shown here you have: $num_row = array(); just before your while loop, making $num_row equal to an empty array. Therefore, $num_row['total'] in your check will not pass and your while loop is skipped. Since, $sleeping_time is set to 0 just before the loop it will output 0. Also, $count_keyword is not defined in the code here.
13th Sep 2017, 8:34 AM
ChaoticDawg
ChaoticDawg - avatar
0
thanks for your respon, i'm try remove $sleeping_time=0, then my code return NULL It looks like $sleeping_time+=2 does not work
13th Sep 2017, 8:53 AM
Lương Văn Của
Lương Văn Của - avatar
0
so it waits until $num_row['total'] >= $count_keyword then ends the loop (about 40s)
13th Sep 2017, 8:56 AM
Lương Văn Của
Lương Văn Của - avatar