aznjay Posted September 17, 2008 Share Posted September 17, 2008 $sql = 'SELECT * FROM phptut ORDER BY id ASC'; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { echo '<div id="tutorial"><a href="'.$_SERVER['REQUEST_URI'].'&id='.$row['id'].'">'.$row['title'].'</a></div>'; function strLength($str,$len){ $lenght = strlen($str); if($lenght > $len){ return substr($str,0,$len).'...'; }else{ return $str; } } $str = $row['article']; //The fist part is the string, the second part is how long it can be echo '<div id="tutorial2">'; echo strLength($str,150); echo '<a href="'.$_SERVER['REQUEST_URI'].'&id='.$row['id'].'">Read More</a>'; echo '</div>'; } } ?> CHeck this error out: http://alltraxx.uni.cc/index.php?page=phptuts "Fatal error: Cannot redeclare strlength() (previously declared in /home/jayjay/public_html/phptuts.php:37) in /home/jayjay/public_html/phptuts.php on line 37" I don't know how to fixe it. Link to comment https://forums.phpfreaks.com/topic/124695-another-crazy-day/ Share on other sites More sharing options...
HeaDmiLe Posted September 17, 2008 Share Posted September 17, 2008 Simple... change the nema of function... this have been used somewhere else Link to comment https://forums.phpfreaks.com/topic/124695-another-crazy-day/#findComment-644069 Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 It looks like you're including this phptuts.php file. Maybe you're including it more than once? Link to comment https://forums.phpfreaks.com/topic/124695-another-crazy-day/#findComment-644070 Share on other sites More sharing options...
PFMaBiSmAd Posted September 17, 2008 Share Posted September 17, 2008 Your function definition is inside of your while() loop. Every iteration of the loop redefines the function. Why would you put a function definition inside of a loop? Link to comment https://forums.phpfreaks.com/topic/124695-another-crazy-day/#findComment-644076 Share on other sites More sharing options...
HeaDmiLe Posted September 17, 2008 Share Posted September 17, 2008 Your function definition is inside of your while() loop. Every iteration of the loop redefines the function. Why would you put a function definition inside of a loop? Oh, you're totally right, I haven't seen it... bannally mistake, sry Link to comment https://forums.phpfreaks.com/topic/124695-another-crazy-day/#findComment-644082 Share on other sites More sharing options...
aznjay Posted September 17, 2008 Author Share Posted September 17, 2008 Your function definition is inside of your while() loop. Every iteration of the loop redefines the function. Why would you put a function definition inside of a loop? hahha sorrie but i don't get what you said..i'm newbie..i need a quick fixage Link to comment https://forums.phpfreaks.com/topic/124695-another-crazy-day/#findComment-644083 Share on other sites More sharing options...
HeaDmiLe Posted September 17, 2008 Share Posted September 17, 2008 $sql = 'SELECT * FROM phptut ORDER BY id ASC'; $result = mysql_query($sql); function strLength($str,$len){ $lenght = strlen($str); if($lenght > $len){ return substr($str,0,$len).'...'; }else{ return $str; } } while($row = mysql_fetch_assoc($result)) { echo '<div id="tutorial"><a href="'.$_SERVER['REQUEST_URI'].'&id='.$row['id'].'">'.$row['title'].'</a></div>'; $str = $row['article']; //The fist part is the string, the second part is how long it can be echo '<div id="tutorial2">'; echo strLength($str,150); echo '<a href="'.$_SERVER['REQUEST_URI'].'&id='.$row['id'].'">Read More</a>'; echo '</div>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/124695-another-crazy-day/#findComment-644090 Share on other sites More sharing options...
aznjay Posted September 17, 2008 Author Share Posted September 17, 2008 This is exactly what I need it went blank..but now for some reason it works..thnx head Link to comment https://forums.phpfreaks.com/topic/124695-another-crazy-day/#findComment-644095 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.