Jump to content

Database section article link


synking

Recommended Posts

I have two tables in mysql one that holds sections of articles and another that actually holds the articles them selves.

 

I am trying to setup the home page so that the nav links menu on the left has the sections that are in the database and when you click on the link it shows all the articles related to that section but i don't know how to go about doing this i now how the get the article it self by doing the link similar to this

 

<a href="index.php?content=body.php

 

could i just add a link in there that will to the sections table.

Link to comment
https://forums.phpfreaks.com/topic/116643-database-section-article-link/
Share on other sites

my site is quite simple, actually. the table that holds my articles also holds which category they fall under. I then have an "allowed array", or an array of allowed words that can be in the $_GET['page']. If what the person is wanting isn't in the allowed, it shows them the main page, otherwise, it shows articles for that category, by adding the $_GET[] var in my query.  Did I lose you?

sample code:

<?php
$allowed_pages = array("home", "about", "contact", "humor", "vids", "pics");
if (isset($_GET['page']) && in_array($_GET['page'], $allowed_pages)){
$page = $_GET['page'];
}
else{
$page = "home";
}
$sql = "SELECT * FROM `my_site` WHERE `category`='$page';";
?>

ok i need some more help.... what i am trying to do is have two sections in a div that use php one is a nav with links to the sections specified in the database and then the body that has the articles from the corresponding section.

 

i have this code updated from the one before.

 

<?PHP

require_once ('../includes/DbConnector.php');


$connector = new DbConnector();

$allowed_pages = array("news", "content", "contact", "service", "downloads"); 

if(isset($_GET['page']) && in_array($_GET['page'], $allowed_pages)) {

         $page = $_GET['page'];

} else {

       $page = "news";
}

$result = $connector->query('SELECT s.id AS `sectionID`,
                             s.name, s.parentid, 
                             a.id AS `articleID`, 
                             a.thedate, a.title, a.section, a.thearticle
                             FROM cmssection s
                             LEFT JOIN cmsarticles a ON (a.section = s.id)
                             WHERE s.id = 2');

    if(!$result) {

        echo ('<p class="error"> Error From SQL query: ' .$connector->getSqlError(). '</p>');

    } else {

        while ($row = $connector->fetchArray($result)) {

          echo ('<p>');
          echo ('<a href="test.php?content=" '.$row['section'].'>'.$row['name'].'</a>');

        }
    }
?>

but it just prints at all of the articles in the database not the ones in that specified section.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.