RJP1 Posted July 10, 2010 Share Posted July 10, 2010 Hi guys, I've been teaching myself OOP based PHP for a CMS project. I was wondering if you could help me with a slight sticking point? I have 2 tables, one for articles, one for sections. In the articles table, each article is given a section ID (rather than the section name). When I output articles in a loop (limit of 3, to test) I can get the title, the section ID and the content. However, how do I reference the section table to get the corresponding section ID name? I've attached my code so you can see: public function display_public() { require_once('includes/DbConnector.php'); $connector = new DbConnector(); $result = $connector->query('SELECT * FROM article ORDER BY created DESC LIMIT 3'); if ( $result !== false && mysql_num_rows($result) > 0 ) { while ( $a = mysql_fetch_assoc($result) ) { $title = stripslashes($a['title']); $section = stripslashes($a['section']); $bodytext = stripslashes($a['bodytext']); #### Article variables are out put here as part of the loop #### } Thanks for the help! RJP1 Quote Link to comment https://forums.phpfreaks.com/topic/207368-referencing-a-separate-mysql-table-from-within-a-while-loop/ Share on other sites More sharing options...
RJP1 Posted July 10, 2010 Author Share Posted July 10, 2010 Nevermind! I figured it out. Basically, I solved it earlier but didn't change the $result variable within the loop which somehow conflicts with the main $result query in the loop... Cheers anyway! Quote Link to comment https://forums.phpfreaks.com/topic/207368-referencing-a-separate-mysql-table-from-within-a-while-loop/#findComment-1084158 Share on other sites More sharing options...
PFMaBiSmAd Posted July 10, 2010 Share Posted July 10, 2010 The variable named $result is the same variable throughout the scope of that code. If each reference to the same variable name was not to the same variable, it would be impossible to write most code (loops or no loops.) Quote Link to comment https://forums.phpfreaks.com/topic/207368-referencing-a-separate-mysql-table-from-within-a-while-loop/#findComment-1084162 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.