I recently set up a lamp server in an attempt to create a website. My code is as follows.
<!DOCTYPE html> <html> <head> </head> <body> <h1>PHP connect to MySQL</h1> <?php $query = "SELECT * FROM nes"; $db = mysqli_connect('localhost','root','password','gameRankings'); $result = mysqli_query($db, $query); $row = mysqli_fetch_array($result); while ($row < mysqli_fetch_array($result)) { echo $row['ranking'] . ' ' . $row['name'] . ': ' . $row['review'] . ' ' . $row['releaseYear'] .'<br>'; } mysqli_close($db); ?> <h1>PHP connect to MySQL</h1> </body> </html>
The program runs fine and outputs the data I want when I run it using php index.php however when I go to load the site into a browser nothing displays except the heading. If I were to move my the $db connector line to the top of the code then not even the heading displays. There are no errors being thrown in the apache logs either. I have no idea what I'm doing wrong here!
Replace
$row = mysqli_fetch_array($result);
while ($row < mysqli_fetch_array($result)) {
With
while ($row = mysqli_fetch_array($result)) {
That will update $row
each loop, with the value from database, and display the info you want.
Do these two steps and you will get your result .
Remove this statement :
$row = mysqli_fetch_array($result);
Re-write the while statement as :
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){ //Your Code }
If you still got no result , then check your database tables whether they have any records or not .
I wish I had a good answer as to what fixed this but I came in this morning to it functioning properly. I also made the other adjustments that were mentioned. This was my first post and I really appreciate the feedback everyone gave!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.