嘿,大家希望有人可以帮助。PHP:查询显示链接
我使用substr给文章的摘要。现在的问题是,当你点击链接查看整篇文章时,你仍然可以看到substr版本。现在,这显然是因为代码的方式。
我需要做另一个查询,说如果有人点击链接,然后显示没有substr的完整文章。我不知道如何去做这个任何人都可以帮忙?虽然我正在学习我的PHP知识是相当有限的。
<?php
class MyCMS
{
function get_content($id = "")
{
if ($id != ""):
$id = mysql_real_escape_string($id);
$sql = "SELECT * FROM content WHERE blog_id = '$id'";
$return = '<p><a href="index.php"> Go Back To Content Page</a></p>';
else:
$sql = "SELECT blog_id, title, date, body FROM content ORDER BY blog_id DESC LIMIT 0, 3";
endif;
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) !=0):
while($row = mysql_fetch_assoc($res))
{
echo '<div id="roundedbox"><h2><a href="index.php?id=' . $row['blog_id'] . '">' . $row['title'] . ' </a></h2>';
echo '<div id="date"><h5><p>' . $row['date'] . '</p></h5></div>';
echo substr('<p>' . $row['body'] . '</p>',0, 90)." .... "." read more </div>";
}
else:
echo '<p> UH OOH! THERE IS NO SUCH PAGE IT DOES\'T EXIST </p>';
echo $return;
endif;
}
}
?>
嘿感谢回到我身边。我应该在这里把这些价值传递给我的班级吗? (isset($ _ GET ['id'])): echo $ obj-> get_content($ _ GET ['id']);其他: echo $ obj-> get_content(); endif; ?> – user2480085
yes,像'$ obj-> get_content($ _ GET ['id'],TRUE)'摘录,'$ obj-> get_content($ _ GET ['id'])'完整发帖 –
或if通过URL查询字符串'$ obj-> get_content($ _ GET ['id'],$ _GET ['excerpt'])'传递标志,并使URL查询字符串像'http://mydomain.com/myscript。 php?id = 123&excerpt = TRUE'摘录,'http://mydomain.com/myscript.php?id = 123&excerpt = FALSE' for full post –