1

So I have a database table, named todolist, and I want to display the whole to do list in a box. What I have right now is this:

$db = (INFO HERE :));    
$sql = "SELECT * FROM todolist";
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) == 0) {
  echo "There is nothing else to do! :)";
} else {
}

What do I put in the else, for it to display everything on a list? Thanks

1
  • what list? what you want as expected outcome? Please show. A sample:-else { while($row = mysqli_ftech_assoc($result)){echo "<pre/>";print_r($row);} } Commented Feb 14, 2017 at 6:30

3 Answers 3

1

try something like below:

 <?php
    $db = (INFO HERE :));    
    $sql = "SELECT * FROM todolist";
    $result = mysqli_query($db, $sql);
    if(mysqli_num_rows($result) == 0) {
        echo "There is nothing else to do! :)";
    } 
    else{
        ?>
        <ul>
            <?php
            while($row = mysqli_fetch_assoc($result)){
                ?>
                  <li><?php echo $row["yourColumnName"] ?></li><?php                
            }?>
            </ul><?php
        }

?>

Sign up to request clarification or add additional context in comments.

Comments

1
$sql = "SELECT * FROM todolist";
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) == 0) {
   echo "There is nothing else to do! :)";
   exit;
}

while ($row = mysql_fetch_assoc($result)) {
  // To see all data
       // print_r($row);
  //  to print single column value 
      //echo $row['id];
}

Comments

1
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    //Do something here  with $row array , for example print_r
print_r($row);
}

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.