Jump to content

Another crazy day..


aznjay

Recommended Posts

    $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

    $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

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.