Hi there, my first echo in the code below returns the page title but the second echo doesn't - I can't work out why. Can anyone help please? <?php // Retrieve the page's name: $q = "SELECT title FROM pages"; $r = mysqli_query ($dbc, $q); echo 'Test the $row ' . $row[0] . '<br />'; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo 'Title ' . $row[0]; } // End of while loop. PHP: Thank you, Colin
Mate, you are misusing the fetch array wrongly, the loop will go through each row one by one rather than you trying to access the index of 0 of the array. Where it says $row inside the square brackets you will need to have the field name of the database for example $row['page_title'];
<?php // Retrieve the page's name: $q = "SELECT title FROM pages"; $r = mysqli_query ($dbc, $q); echo 'Test the $row ' . $row['page_title'] . '<br />'; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo 'Title ' . $row['page_title']; } // End of while loop. PHP: