3. Readmore Menu Content and Readmore Category Article

1.crud.php

<?php

class Crud {

    public $conn;

    public function __construct() {
        $this->conn = mysqli_connect("localhost", "root", "", "fresh");
        if (mysqli_connect()) {
            //echo "Connect Successfully";
        } else {
            die("connection error");
        }
    }

    /* This is for readmore menu content */
    public function readMenuContent($table, $id) {
        $query = mysqli_query($this->conn, "SELECT * FROM $table WHERE menu_id=$id AND status= 1");
        if (mysqli_num_rows($query) > 0) {
            return mysqli_fetch_assoc($query);
        } else {
            return false;
        }
    }
    
    /* This is for readmore Article */
    public function readArticle($table, $id) {
        $query = mysqli_query($this->conn, "SELECT * FROM $table WHERE art_id=$id AND status = 1");
        if (mysqli_num_rows($query)) {
            return mysqli_fetch_assoc($query);
        } else {
            return false;
        }
    }

}

$obj = new Crud();

2.content.php

<div class="content1">
    <div class="content1_box1 flt_lt">

        <?php
        /* This is for menu content */
        if (isset($_REQUEST['menu_id'])) {
            $content = $obj->MenuContent("menus", $_REQUEST['menu_id']);
            //echo $content["menu_content"];

            /* Start from this here for Readmore content */
            extract($content);
            $convert_array = explode(' ', $menu_content);
            //print_r($convert_array);
            if (count($convert_array) <= 210) {
                echo "<p>$menu_content</p>";
            } else {
                $slice = array_slice($convert_array, 0, 209);
                echo "<p>" . implode(' ', $slice) . "<a style=text-decoration:none;color:red; href=index.php?id=$menu_id>&nbsp;&nbsp;Read More</a> </p>";
            }
        } elseif (isset($_REQUEST['id'])) {
            $readmore = $obj->readMenuContent("menus", $_REQUEST['id']);
            //print_r($readmore);
            echo $readmore['menu_content'];
        } /* finish line Readmore content */



        /* This is for category articles */
        if (isset($_REQUEST['cat_id']) ? $_GET['cat_id'] : null) {
            $articles = $obj->CatArticle("articles", $_REQUEST['cat_id']);
            //echo "<pre>";
            //print_r($articles);
            foreach ($articles as $article) {
                extract($article);
                echo "<h2>" . $article["art_title"] . "</h2>";
                //echo "<p>" . $article["art_content"] . "</p>";

                /* Start from this here for Readmore Article */
                $art_convert_array = explode(' ', $art_content);
                //print_r($art_convert_array);
                if (count($art_convert_array) <= 160) {
                    echo "<p>" . $art_convert_array["art_content"] . "</p>";
                    //echo "<p>$art_content</p>";
                } else {
                    $art_slice = array_slice($art_convert_array, 0, 159);
                    echo "<p>" . implode(' ', $art_slice) . "<a style=text-decoration:none;color:red; href=index.php?art_id=$art_id>&nbsp;&nbsp;Read More</a> </p>";
                }
            }
        } elseif (isset($_REQUEST['art_id'])) {
            $artReadmore = $obj->readArticle("articles", $_REQUEST['art_id']);
            echo "<h2>" . $artReadmore['art_title'] . "</h2>";
            echo "<p>" . $artReadmore['art_content'] . "</p>";
        } /* finish line Readmore Article */
        ?>

        <br/>
    </div>

Output:
readmore

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s