I am having a problem with a for loop just like the title says.
Want I want to do is query the database for instances of posts where the conditions are met. Then for each one set $postTitle and $postContent to the according table columns. If my words are a bit clumsy I hope my code can do better. Any help is appreciated.
p.s. dont worry about $referrer and $pageName those variables are solid. I just want the output to do what I want.
http://pastie.org/430222 - The code
The image of the table - http://www.newcustomers2you.com/table.jpg
Having a problem with a for loop...and need help
Moderator: General Moderators
-
inquisitivedzign
- Forum Newbie
- Posts: 4
- Joined: Sat Mar 28, 2009 9:51 pm
Re: Having a problem with a for loop...and need help
Code: Select all
<?php
}
else {
foreach($row2 as $key => $value) {
$postTitle = $row2['postTitle'];
$postContent = $row2['postContent'];
?>
<div id="about" class="post">
<h2 class="title"><?php echo $postTitle; ?>
</h2>
<div class="entry">
<?php echo $postContent; ?>
</div>
Code: Select all
<?php
}
else {
foreach($row2 as $key => $value) {
echo '<div id="about" class="post">
<h2 class="title">' . $row2['postTitle'] . '</h2>
<div class="entry">' .
$row2['postContent'] . '
</div>
?>Hope that helps.
-
inquisitivedzign
- Forum Newbie
- Posts: 4
- Joined: Sat Mar 28, 2009 9:51 pm
Re: Having a problem with a for loop...and need help
my loop actually already did what that does. Except it is slightly cleaner.
The only problem I have right now is that It displays the same output 6times...if I output key as value then it goes through the table outputting each key as the title and each value as the content.
I want it only to display postTitle and Content
The only problem I have right now is that It displays the same output 6times...if I output key as value then it goes through the table outputting each key as the title and each value as the content.
I want it only to display postTitle and Content