Hello Everyone!
I'm very new to PHP, and it's making concatenation extremely frustrating.
I have scrolling news stories on my website, whereby a user clicks a headline button and moves the corresponding story into view.
Each story looks like so:
<div id="story1">
<h1>Headline 1</h1>
<p>Text1 text1 text1</p>
</div>
And each button looks like so:
<div id="button1">Headline 1</div>
I'm trying to use PHP to generate a new div and new button for each story in the database.
I've looked at the do...while loop, which seems to make sense, but I keep getting nothing but errors from the browser.
Could somebody please show me the syntax for adding a new <div> block (with any h1's and p's) for each record?
I thank you for your time.
Arlen
Trouble with Concatenation
Moderator: General Moderators
-
patrickmvi
- Forum Commoner
- Posts: 32
- Joined: Mon Jun 22, 2009 6:45 am
- Location: Fort Lauderdale, FL
Re: Trouble with Concatenation
Can you post the an example of what you'd ultimately want to create? Basically the end result of what you're looking to achieve? Then maybe I can better understand what you're trying to achieve and provide better insight.
-
pkunzipula
- Forum Newbie
- Posts: 8
- Joined: Mon Jun 22, 2009 2:23 am
Re: Trouble with Concatenation
Thanks for responding, Patrick. Here is the code for creating this section. I have 8 stories, so the div ID of s1 and b1 should change to s2/b2, s3/b3...each time the loop runs. I know this requires using a variable in place of the number 1 and then incrementing it for each loop, but this is where the concatenation gets messy for me.
I uploaded a screenshot here .... http://skiweiner.webs.com/
Thank you again!
I uploaded a screenshot here .... http://skiweiner.webs.com/
Thank you again!
Code: Select all
<?php
//get the headline and text of the first story
$headline = $row['headline'];
$text = $row['text'];
$getTotal = 'SELECT COUNT(*) FROM topstories';
$i = 1;
?>
<div id="slide">
<?php do { ?>
[size=150][b]<div id="s1">[/b][/size]
<h1><?php echo $headline; ?></h1>
<p><?php echo $text; ?></p>
</div>
<?php
$row = $result->fetch_assoc();
} while ($row);
?>
</div> <!-- end slide -->
<div id="buttons">
<h2>Latest News</h2>
<?php do { ?>
[size=150][b]<div id="b1">[/b][/size]
<?php echo $headline ?>
</div>
<?php
$row = $result->fetch_assoc();
} while ($row);
?>
</div> <!-- end buttons -->