0

This while loop causes a Fatal error: Maximum execution time of 30 seconds exceeded. The query IS working. I tested the query in phpmyadmin.

Nothing is inside the loop in order to test whether it's content caused the error. It looks like the while loop is overloading. It seems that the script takes too long to load (thinking the query is too extended), not seeing any possibilities the loop to be infinite.

while($tags_db = mysqli_fetch_array(mysqli_query($link, 
"SELECT * 
FROM zk_terms 
WHERE parent_id = 1 AND parent_type = 'archive' AND taxonomy = 'tag'"))){

}
7
  • What are you trying to achieve with the while loop? Commented Apr 27, 2014 at 20:58
  • It's not finite - each iteration you're performing a query and fetching the first row from it. If you didn't put everything into single line it would be obvious for you too. Commented Apr 27, 2014 at 20:58
  • I left nothing inside the while loop to check whether the content of the loop was causing the error. But still without any script inside, it's running into problems. Commented Apr 27, 2014 at 20:59
  • What you're saying @zerkms is that I have to create two lines? First line: $tags_db = mysqli_fetch_array(mysqli_query($link, "SELECT * FROM zk_terms WHERE parent_id = 1 AND parent_type = 'archive' AND taxonomy = 'tag'")) Second line: while($tags_db)? Commented Apr 27, 2014 at 21:01
  • @TomGroot It doesn't matter how many lines you put the query string on... read your answers below. Commented Apr 27, 2014 at 21:01

3 Answers 3

6

You're re-executing the query every iteration, and then mysqli_fetch_array is fetching only the first result each loop. You have to move mysqli_query outside the loop and assign it to a variable.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to modify your code:

$query = mysqli_query($link, 
"SELECT * 
FROM zk_terms 
WHERE parent_id = 1 AND parent_type = 'archive' AND taxonomy = 'tag'");

while($tags_db = mysqli_fetch_array($query)){
 // your code
}

Comments

0

Place your mysqli_query command outside your while and catch the result in a variable. Then use the variable with mysqli_fetch_array in the while .

otherwise, everytime the while condition is examined, the query is run again

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.