I am trying to get all rows in database. My code:
$sql = "SELECT * FROM lectors";
$array = array();
while($row = mysqli_fetch_assoc(mysqli_query($con,$sql))){
echo $row["name"];
}
While I send request, server doesn't reply. Any ideas?
while($row = mysqli_fetch_assoc(mysqli_query($con,$sql))){
This is a never ending loop, your query will execute fine every time and loop will never terminate.
Need I say further?
It is only as good as
while(true)
{
// keep querying my database until i run out of resources
}
Execute the query first and loop over its result only.
And Oh,
While I send request, server doesn't reply
Because, as i said; It is busy running in a circle, has no time to reply.
Try to put the query in a line by itself, such as...
$sql = "SELECT * FROM lectors";
$array = array();
$res = mysqli_query($con,$sql);
while($row = mysqli_fetch_assoc($res)){
echo $row["name"];
}
Doing it in the method you are above will result in each execution of the loop executing the database query.
$conSQL connection?mysqli_query($con,$sql)as a single step before yourwhile, and themysqli_fetch_assoc()in thewhile.... because I'm sure you've never seen a working example or anything in the PHP Docs that combines everything inside thewhile$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');