nonstop328 nonstop328 - 6 months ago 12
PHP Question

got an error with while loop in php

Can anyone help me take a look? I want to fetch a number out but i get this error


Parse error: syntax error, unexpected ';', expecting ']' in E:\Software\Xampp\htdocs\pme\main\user_online.php on line 12


here is my code

<?php

include '../config.php';

$sql= mysqli_query($connection,' select * from session');
$row = mysqli_num_rows($sql);

while($extract = mysqli_fetch_array($sql)){
echo
"<div class='left-total-user-online' id='left-total-user-online'>

total user online : " .$extract[$row = mysqli_num_rows($sql);]. "</div>";

}

?>

Answer

You are making life much more complicated than is necessary. All you need to code is

<?php 

    include '../config.php';

    $sql= mysqli_query($connection,' select * from session');
    $row = mysqli_num_rows($sql);

    echo "<div class='left-total-user-online' id='left-total-user-online'>
            total user online : $row</div>";
    }
?>
Comments