Mr Chris Posted April 22, 2008 Share Posted April 22, 2008 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 More sharing options...
Fadion Posted April 22, 2008 Share Posted April 22, 2008 Where the script stops or what doesnt work? Link to comment https://forums.phpfreaks.com/topic/102307-while-loop-help/#findComment-523859 Share on other sites More sharing options...
Mr Chris Posted April 22, 2008 Author Share Posted April 22, 2008 Hi, I get this message: Fatal error: Cannot use [] for reading in file.php? Thanks Link to comment https://forums.phpfreaks.com/topic/102307-while-loop-help/#findComment-523916 Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 javascript? Link to comment https://forums.phpfreaks.com/topic/102307-while-loop-help/#findComment-523925 Share on other sites More sharing options...
Mr Chris Posted April 22, 2008 Author Share Posted April 22, 2008 Thanks, yep it's part of a javascript, but the error is happening on this php line: $details[] = str_replace(array("\r\n", "\r", "\n"), "\n", $details[]); Cheers Link to comment https://forums.phpfreaks.com/topic/102307-while-loop-help/#findComment-523935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.