Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

PHP MySQLi While loop in php7

Works for me and I'm using php 8.1.2

PHP:
<?php
echo '<b>PHP Version: </b>' . phpversion() . "<br>";
echo'<br>';
$conn = mysqli_connect('localhost', 'username', 'password', 'database');
$query = 'select * from title';
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
    echo $row['name'] . '<br>';
}
?>
/CODE]

output
[CODE]PHP Version: 8.1.2-1ubuntu2.9

1602 A.D.
A-Train 9
banished
builders of egypt prologue
cities skylines
dawn of man
europa universalis III
farcry 3
farming simulator 19
farming simulator 2013
medival dynasty
medival kingdom wars
oligopoly
openttd
planet coaster
railroad corporations
railroad tycoon 2
railroad tycoon 3
railway empire
rising world
rust
saints row IV
sid meier's civilization V
sid meier's railroads
subnautica
the guild II
trainz a new era
transport fever
transport fever 2
tropico 5
tropico 6
valheim
warzone 2100
 
Last edited:
What do you mean with "doesn't work" ? Do you get an error ? Or just an empty result set ? Or something else yet ?
Empty result but spotted my error in the above code by menator01

while ($row = mysqli_fetch_array($result,MYSQL_ASSOC)) {

MYSQLI_ASSOC

doh!!!

Thank you menator01

I'm surprised it worked in php5.6
 
Ah yes, stands to reason that when you use the improved driver you need to use the parameters that go with that driver. I'm a but surprised though that this apparently did not produce a warning or error such as MYSQL_ASSOC not found 🤔
 
Back
Top Bottom