synking Posted July 25, 2008 Share Posted July 25, 2008 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 More sharing options...
jonsjava Posted July 25, 2008 Share Posted July 25, 2008 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? Link to comment https://forums.phpfreaks.com/topic/116643-database-section-article-link/#findComment-599746 Share on other sites More sharing options...
synking Posted July 25, 2008 Author Share Posted July 25, 2008 No didn't lose me but i am not familiar with setting allowed words in the $_GET['something']. and if what your saying is i set the link to use the get method to pull the data with a query in the link or something to that nature. Link to comment https://forums.phpfreaks.com/topic/116643-database-section-article-link/#findComment-599748 Share on other sites More sharing options...
jonsjava Posted July 25, 2008 Share Posted July 25, 2008 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';"; ?> Link to comment https://forums.phpfreaks.com/topic/116643-database-section-article-link/#findComment-599753 Share on other sites More sharing options...
synking Posted July 25, 2008 Author Share Posted July 25, 2008 thanks that is what i thought you ment did not know about the allowed tough that is awesome. Link to comment https://forums.phpfreaks.com/topic/116643-database-section-article-link/#findComment-599758 Share on other sites More sharing options...
jonsjava Posted July 25, 2008 Share Posted July 25, 2008 any time. if you need any other help, send me a message on my site. Link to comment https://forums.phpfreaks.com/topic/116643-database-section-article-link/#findComment-599762 Share on other sites More sharing options...
synking Posted July 28, 2008 Author Share Posted July 28, 2008 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. Link to comment https://forums.phpfreaks.com/topic/116643-database-section-article-link/#findComment-601660 Share on other sites More sharing options...
synking Posted July 28, 2008 Author Share Posted July 28, 2008 can anyone help with this or should i start a new post. Link to comment https://forums.phpfreaks.com/topic/116643-database-section-article-link/#findComment-601921 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.