0

Here is my code

     <?php require_once 'connect.php';

                    $sql = "SELECT * FROM `db-pages`";
                    $result = $mysqli->query($sql) or die($mysqli->error.__LINE__);
                        while ($row = $result->fetch_assoc()) {
   echo($row['pagetitle'].' - To edit this page <a href="editpage.php?id='.$row['id'].'">click here</a><br>');
 }  
                    }
      ?>

I've added a couple more rows to the Database and it's returning them all, apart from id=1 in the DB. Any idea why?

4
  • what is result echo mysqli_num_rows($result) Commented Nov 12, 2012 at 17:01
  • try to check count of returned rows before you do the while, use echo $result->num_rows; Commented Nov 12, 2012 at 17:03
  • @GBD you forgot the i in mysql. @wiiliamsongibson: how many data are there in database? Commented Nov 12, 2012 at 17:03
  • You can find and answer to a similar question [here][1] [1]: stackoverflow.com/questions/2285600/… Commented Nov 12, 2012 at 17:07

2 Answers 2

1

try it like this:

 while ($row = $result->fetch_assoc()) {
   echo($row['pagetitle'].' - To edit this page <a href="editpage.php?id='.$row['id'].'">click here</a><br>');
 }  
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I've added your example above and more than 2 rows in the DB. It is working, but the first row id=1 is never displayed. Any idea why?
what if you printed the mysqli_fetch_assoc(), what is shown? print_r(mysqli_fetch_assoc());
1

Double check the title and ensure it's got nothing that will affect php out-putting it.

Also escape all of your DB output using htmlentities, it makes for good practise in the event someone gets creative.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.