?foru
04-19-2009, 09:19 PM
I'm having a hard time trying to figure out how I can get the $id var in the substr output for /news.php?id=$id
$res = mysql_query ("SELECT * FROM `news` ") or die (mysql_error ());
$id=$r["id"];
// function to shorten the amt of characters to be shown in the news output
function shorten3($var_name2,$var_length2) {
if(strlen($var_name2) > $var_length2) {
return substr($var_name2,0,$var_length2-3)."...<a href=\"/news.php?id=$id\">full story</a>";
} else {
return $var_name2;
}
}
while($r=mysql_fetch_array($res))
{
$id=$r["id"];
$title=$r["title"];
$news=$r["news"];
$short_news = shorten3($news, 100);
echo "<div class=\"news_header_top\">$title</div><div style=\"padding-bottom: 5px;\">$short_news</div>";
}
I've used the function in other places but they linked to a general page and not a page like news.php?id=$id
I tried to move the function right above $short_news so the id could be gotten and the function would be above the variable $short_news that is being created but I received the cannot re-declare function error. Any help would be appreciated, thank you.
$res = mysql_query ("SELECT * FROM `news` ") or die (mysql_error ());
$id=$r["id"];
// function to shorten the amt of characters to be shown in the news output
function shorten3($var_name2,$var_length2) {
if(strlen($var_name2) > $var_length2) {
return substr($var_name2,0,$var_length2-3)."...<a href=\"/news.php?id=$id\">full story</a>";
} else {
return $var_name2;
}
}
while($r=mysql_fetch_array($res))
{
$id=$r["id"];
$title=$r["title"];
$news=$r["news"];
$short_news = shorten3($news, 100);
echo "<div class=\"news_header_top\">$title</div><div style=\"padding-bottom: 5px;\">$short_news</div>";
}
I've used the function in other places but they linked to a general page and not a page like news.php?id=$id
I tried to move the function right above $short_news so the id could be gotten and the function would be above the variable $short_news that is being created but I received the cannot re-declare function error. Any help would be appreciated, thank you.