Thursday, February 27, 2014

Tute 22 : Show category article in category page

Open the category.php file. We write some php code top of the page. We make quarry for category article in "tute" table.


So write this code after " $query_cat_run=mysql_query($query_cat); " code :

--------------------------------------------------------------------------------------------------------------------
$query= "SELECT `id`, `heading`, `image`, `details`, `category` FROM tute WHERE category='html' ";
$query_run=mysql_query($query);
---------------------------------------------------------------------------------------------------------------




After that we write some code in "<div id="body-con-l"></div>" code.

We write this code after "<div id="body-con-l">" line :

------------------------------------------------------------------------------------------------
<?php
            while($query_row=mysql_fetch_assoc($query_run)){
            $heading=$query_row['heading'];
            $details=$query_row['details'];
            $image=$query_row['image'];
            $id=$query_row['id'];
            echo '<h3><a href="detailspage.php?id='.$id.'">'.$heading. '</a></h3>';
            echo '<img src=images/'.$image.' class="h-img">';
            echo $details. '<br><br>';
        }
  ?>
--------------------------------------------------------------------------------------------

Same code we write in index.php file. Now save the file and open google chrome and refresh the "category.php" tab. We see some article. But some problem. Only html article show here. So we make it dynamic.

We write some code in top of page after " require 'connect.inc.php';" code:

------------------------------------------
$n_category= $_GET[category];
-----------------------------------------


After that edit the query line. We replace this code in " category='html' " code

-------------------------------------
category='".$n_category."'
------------------------------------



Save the file and go to browser. Refresh the category.php tab. We see no article show in left side. So our work is done. Now we do some work in index.php file.

No comments :

Post a Comment