Mysqli Only Shows 1 Result Error

LeChris

Proverbs 3:5
Sep 30, 2013
2,786
1,395
So basically it only 1 result appears
Code:
<div class="block">
<div class="navbar navbar-inner block-header">
<div class="muted pull-left">&nbsp;&nbsp;&nbsp;&nbsp;<i class='icon-download'></i>Dashboard Updates</div>
</div>
<div class="block-content collapse in">
<?php
$announce_fetch = "SELECT * FROM cerberus_announcements ORDER by Id";
$announce_result = $mysqli->query($announce_fetch);
$announce = $announce_result->fetch_array(MYSQLI_ASSOC);
echo '<br>';
echo '<div class="alert alert-';
echo $announce["Status"];
echo 'alert-block">';
echo '<h4>';
echo $announce["Title"];
echo '</h4>';
echo '<p>';
echo $announce["Content"];
echo '<br>&nbsp;-';
echo $announce["Author"];
echo '</div></p>';
$announce_result->free();
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
?>
w636.png

BC9F63q.png
\
No errors are displayed or logged
 

Nehalem

Aug 31, 2013
293
47
Try this;

PHP:
<?php
$announce_fetch = "SELECT * FROM cerberus_announcements ORDER by Id";
$announce_result = $mysqli->query($announce_fetch);
while($announce = $announce_result->fetch_array(MYSQLI_ASSOC)) {
echo '<br>';
echo '<div class="alert alert-';
echo $announce["Status"];
echo 'alert-block">';
echo '<h4>';
echo $announce["Title"];
echo '</h4>';
echo '<p>';
echo $announce["Content"];
echo '<br>&nbsp;-';
echo $announce["Author"];
echo '</div></p>';
}
$announce_result->free();
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
?>

Read more about it here:
 

LeChris

Proverbs 3:5
Sep 30, 2013
2,786
1,395
Try this;

PHP:
<?php
$announce_fetch = "SELECT * FROM cerberus_announcements ORDER by Id";
$announce_result = $mysqli->query($announce_fetch);
while($announce = $announce_result->fetch_array(MYSQLI_ASSOC)) {
echo '<br>';
echo '<div class="alert alert-';
echo $announce["Status"];
echo 'alert-block">';
echo '<h4>';
echo $announce["Title"];
echo '</h4>';
echo '<p>';
echo $announce["Content"];
echo '<br>&nbsp;-';
echo $announce["Author"];
echo '</div></p>';
}
$announce_result->free();
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
?>

Read more about it here:
Thanks! Works perfectly, I will be looking into the link too ,3
 

IntactDev

Member
Nov 22, 2012
399
71
The reason it was only showing one result is because your code wasn't repeating itself to show more results. You would need to use either the while function or the for function to repeat the part of the code that constructs the HTML code and echos the results.
 

Users who are viewing this thread

Top