Jump to content
Pardon our ads (a necessary update) ×

While loop help?


Mr Chris

Recommended Posts

Hello,

 

Can someone help me with some php code.  I'm getting some text out of my database and using it in a while loop.

 

I then want to take the text and grab the first two paragraphs and output them.  Can someone please help me?

 

Thanks

 

// format: src, alt, text
imgArray = [
<?php 
// select all records ordered by date 
$r = mysql_query("Select story FROM  stories ORDER BY story_id LIMIT 6");
while($topStory = mysql_fetch_array($r)) {

// get body_text for two paragraphs
   $details[] = $topStory['story'];
   
// standardise new lines for two paragraphs
   $details[] = str_replace(array("\r\n", "\r", "\n"), "\n", $details[]);
   
// seperate paragraphs
    list($para1[], $para2[]) = explode("\n\n", $details[]);

}
?> 
['<? echo $para1['0']; ?></p><p><? echo $para2['0']; ?>'],
['<? echo $para1['1']; ?></p><p><? echo $para2['1']; ?>'],
['<? echo $para1['2']; ?></p><p><? echo $para2['2']; ?>'],
['<? echo $para1['3']; ?></p><p><? echo $para2['3']; ?>'],
['<? echo $para1['4']; ?></p><p><? echo $para2['4']; ?>']
];

Link to comment
https://forums.phpfreaks.com/topic/102307-while-loop-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.