EternalSorrow Posted September 19, 2009 Share Posted September 19, 2009 I found this nice snippet of code to limit the output of my series descriptions to the first sentence, but I've run into a snag. I want to be able to use the code in a "repeat region," but I receive this error message on the attempt: Fatal error: Cannot redeclare first_sentence() (previously declared) Is there any way to make this snippet of code repeat friendly? Here's what I have so far: <?php $query = "SELECT * FROM series WHERE category = 'Animanga' ORDER BY id desc LIMIT 2 "; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { extract($row); function first_sentence($plot) { $pos = strpos($plot, '.'); return substr($plot, 0, $pos+1); } echo '<li><a href="counter.php?id='.$id.'">'.$series.'</a><br> '.first_sentence($plot).''; } ?> Link to comment https://forums.phpfreaks.com/topic/174807-redeclare-first_sentence/ Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 move the actual function out of the while statement. Only need to call the function from within the loop. Link to comment https://forums.phpfreaks.com/topic/174807-redeclare-first_sentence/#findComment-921238 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.