Hello,
I am a web designer - not a developer but I have always wanted to expand my knowledge and attempt to learn PHP + SQL.
In doing so, I have been very successful doing the backend to my website, but I got stuck on what seems to be a very stupid issue.
PHP Code:
$query = "SELECT comment, name, company FROM companies WHERE company='$myPage' ORDER BY id DESC";
$result = mysql_query($query) or die(mysql_error());
$box = 1;
while($row = mysql_fetch_array($result)){
$row = mysql_fetch_array($result);
if ($box==1) {
$box = 0;
} else {
$box = 1;
}
echo "<div id='recentBox" . (1+$box) . "'>";
echo "<h2>From: " . $row['name'] . "<br />";
echo "Company: " . $row['company'] . "<br />";
echo "Comments: " . $row['comment'] . "</h2>";
echo "</div>";
}
?>
For some reason, the while loop is only half working. It's supposed to display all the comments from an individual company. It's organizing and grouping fine, but it doesn't display all the comments it's supposed to.
Instead of using the while loop, I used a for loop which actually worked out great, but then I am stuck with a fixed amount of comments being displayed.
What is wrong with my while loop?
Thanks!