Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:显示链接的查询_Php_Sql_Content Management System - Fatal编程技术网

PHP:显示链接的查询

PHP:显示链接的查询,php,sql,content-management-system,Php,Sql,Content Management System,希望有人能帮上忙 我正在使用substr提供文章摘要。现在的问题是,当您单击链接查看整篇文章时,仍然会看到substr版本。这显然是因为代码的方式 我需要做另一个查询,如果有人点击链接,然后显示完整的文章,而不显示substr。我不知道该怎么办有人能帮忙吗?虽然我在学习,但我的PHP知识相当有限 <?php class MyCMS { function get_content($id = "") { if ($id != ""): $id = mysql_real

希望有人能帮上忙

我正在使用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;  

}


}
?>

向函数中添加另一个参数,以确定它是返回全文还是节选:

<?php
class MyCMS 
{
function get_content($id = "", $excerpt = FALSE)
{
    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>';
            if ($excerpt):
                echo substr('<p>' . $row['body'] . '</p>',0, 90)." .... "." read more </div>";
            else:
                echo '<p>' . $row['body'] . '</p>';

        }
        else:
            echo '<p> UH OOH! THERE IS NO SUCH PAGE IT DOES\'T EXIST </p>'; 
            echo $return;
        endif;  

}


}
?>

我不认为你想用PHP来做这件事,因为当你用PHP做这件事时,你必须刷新整个页面

我建议您为此使用Javascript,比如jQuery库


使用这种方法,Google仍然会为所有内容编制索引。

通常,您会将文章封装到一个数据类中(别名“Model”,请参见MVC架构)。该模型保存文章的所有数据,并有一个方法返回文章的摘要或长版本。要确定客户端希望看到的版本,请向URL传递另一个参数

class Article {
    protected $text;
    protected $title;

    public __construct ($title, $text) {
        $this->title = $title;
        $this->text = $text;
    }        

    /** 
     * Returns the short excerpt of the article
     */
    public getShortAbstract () {
        // your substr() function
    }        

    /**
     * Returns the full article
     */
    public getText () {
        return $this->text;
    }
}

嘿,谢谢你回复我。我应该在这里传递这些值吗?是的,像
$obj->get_content($$u get['id'],TRUE)
对于摘录,
$obj->get_content($$u get['id'])
对于全文,或者如果通过URL查询字符串传递标志,
$obj->get_content($$u get['id'],$u get['extract'])
并将URL查询字符串设置为
http://mydomain.com/myscript.php?id=123&excerpt=TRUE
对于摘录,
http://mydomain.com/myscript.php?id=123&excerpt=FALSE
用于全文
class Article {
    protected $text;
    protected $title;

    public __construct ($title, $text) {
        $this->title = $title;
        $this->text = $text;
    }        

    /** 
     * Returns the short excerpt of the article
     */
    public getShortAbstract () {
        // your substr() function
    }        

    /**
     * Returns the full article
     */
    public getText () {
        return $this->text;
    }
}