Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Richard Duffy
16,488 PointsHelp!
My while loop is not working it is 01 25 AM I am shattered and I just want this to work here is my code
<?php
include_once 'connect.php';
doDB();
$get_acct = "SELECT id, account_title FROM account_list ORDER BY account_title DESC ";
$res_acct = mysqli_query($mysqli,$get_acct)or die(mysqli_error($mysqli));
if(mysqli_num_rows($res_acct) < 1) {
$display_block = "<p><em>No accounts exist</em></p>";
} else {
$display_block = <<<END_OF_TEXT
<table>
<tr>
<th><h4>Account Name</h4></th>
</tr>
END_OF_TEXT;
$row = mysqli_fetch_array($res_acct)
while($r = mysqli_fetch_array($res_acct)
$display_block .= <<<END_OF_TEXT
<tr>
<td><a href="showaccount.php?account=$id">
<strong> $name></strong>
</a>
<strong>$id</strong>
END_OF_TEXT;
}
mysqli_free_result($res_acct);
mysqli_close($mysqli);
$display_block .= "</table>";
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Account Lists</title>
</head>
<body>
<?php echo $display_block;?>
</body>
</html>
3 Answers
Richard Duffy
16,488 PointsThis is all it gives me: Account Name
na> 1
Dave McFarland
Treehouse TeacherI'm no PHP expert, but this code doesn't look right:
while($r = mysqli_fetch_array($res_acct)
Shouldn't there be an extra closing ) at the end, and a { ?
There should also be a closing } at the end of the while statement.
Richard Duffy
16,488 Pointswhile($row = mysqli_fetch_array($res_acct)) {
$name = $row['account_title'];
$id = $row['id'];
}
There is, I am really tired and keep making mistakes, it is only displaying one result not all of them from the data base, there are no php errors or syntax errors. Thanks.