PHP/SQL Stuck in an inifinite while loop possibly due to a bad query?

php mysqli multiple queries at once
php mysql query result
php while loop array
php mysql query inside while loop
mysql multiple queries in one statement
do while loop in php
mysqli_multi_query vs mysqli_query
mysqli_multi_query not working
$query = "SELECT DISTINCT users FROM computers WHERE ComputerName='EN4073254W'";
while ($user_name = mysqli_fetch_array(mysqli_query($cxn, $query))) { // print out user names
    printf("<li><a href='%s'>%s</a>\n", $user_name[0], $user_name[0]);
}

I am running a query to check for distinct users based on ComputerName all of this is ran through a while loop, I did this by following an example I found here. Running this query in phpMyAdmin results in correct output, so I'm roughly confident that my query is correct. I've also spent the time chopping through this line by line in phpStorm's debugger, but alas it gives me no good insight into what is happening (it just repeats itself over and over again).

<li><a href='foo'>foo</a>
<li><a href='foo'>foo</a>
<li><a href='foo'>foo</a>
<li><a href='foo'>foo</a>
<li><a href='foo'>foo</a>
<li><a href='foo'>foo</a>
<li><a href='foo'>foo</a>
...

The desired result should be something like this

<li><a href='foo'>foo</a>
<li><a href='bar'>bar</a>

You are executing query in while loop so its running infinite time.

 while ($user_name = mysqli_fetch_array(mysqli_query($cxn, $query))) // runs infinite time 

change the above line to

$result = mysqli_query($cxn, $query);
while ($user_name = mysqli_fetch_array(($result,MYSQLI_NUM)))

mysqli::multi_query - Manual, mysqli::multi_query -- mysqli_multi_query — Performs a query on the database execute multi query */ if ($mysqli->multi_query($query)) { do { /* store first while​(mysqli_next_result($this->sqlLink)); ? can create infinite look in some cases I was developing my own CMS and I was having problem with attaching the database' sql file. I thought mysqli_multi_query got bugs where it crashes my MySQL server. I tried to report the bug but it showed that it has duplicate bug reports of other developers. To my surprise, mysqli_multi_query needs to bother with result even if there's none.

$query = "SELECT DISTINCT users FROM computers WHERE ComputerName='EN4073254W'";
$stmtQuery = mysqli_query($cxn, $query);
while ($user_name = mysqli_fetch_array($stmtQuery)) { 
    printf("<li><a href='%s'>%s</a>\n", $user_name[0], $user_name[0]);
}

Sql query inside while loop - PHP, how many rows do you expect to be returned by the result set? For now not many​, but in the future probably thousands. An infinite loop is nothing but a sequence of instructions which loops endlessly, either due to the loop having no terminating condition, having one that can never be met, or one that causes the loop to start over. The syntax is as follows using the while loop: Adblock detected 😱 My website is made possible by displaying online

Your query is fine, but you're re-executing it every time you check to see if you exit the while loop and fetching the first item.

You want something more like: $users = mysqli_fetch_array(mysqli_query($cxn, $query)) foreach ($users as $user_name) { ... }

Top 10 MySQL Mistakes Made By PHP Developers, Watch out also for SQL queries within PHP loops. Normally, it's more effective to run a query then loop  Sunstate Management Solutions is an IT service provider. Get answers from your peers along with millions of IT pros who visit Spiceworks. Has anyone else experienced Outlook 2016 stuck in an authentication loop when you have multi-factor authentication (MFA) enabled on Office365? The sequence is that Outlook displays the modern authentication

MySQL Bugs: #92387: SHOW SESSION VARIABLES stuck in state , Type '\c' to clear the current input statement. mysql> create database if not exists test; Query OK, 1 row  I am running a query to check for distinct users based on ComputerName all of this is ran through a while loop, I did this by following an example I found here. Running this query in phpMyAdmin results in correct output, so I'm roughly confident that my query is correct.

PHP Loops, dowhile - loops through a block of code once, and then repeats the loop as long as the specified condition is true; for -  This recursive function helps the programmers to deploy the same set of code several times as and when required. Some SQL programming languages limit the recursion depth to prevent an infinite loop of procedure calls from causing a stack overflow, which slows down the system and may lead to system crashes.

Infinite loop, In computer programming, an infinite loop (or endless loop) is a An infinite loop occurs when the condition will never be met, due to some inherent loops without causing the entire program to be stuck in an infinite loop. Example in PHP:. Due to the urgency, I achieved the default value problem through Abinitio, like this. I generated a single record with default value as 0 and i did a full outer join with the output of the select query, so when no rows returned i get 0 as default value, when value is coming from select query, I choose only the output of the select query.

Comments
  • You've put the query execution in the loop condition. That's why.
  • Could you provide an example as an answer, please?
  • This sort of works, but spits out double of everything and it seems to cause my server to hang.