I have a class content.class.php
<?php
class Content {
// News
function newsCategory()
{
$sql_category = mysql_query("Select `name` FROM Category WHERE sectionName='News'");
$category = array(); //create empty array
while($categoryRow = mysql_fetch_assoc($sql_category))
{
$category[] = $categoryRow; //append the whole $categoryRow array in $category
}
return $category;
} // end newsCategory()
function news($category_data)
{
$sql_news = mysql_query("SELECT id,title FROM Content WHERE sectionName='News' AND name='".$category_data."'");
$news = array();
while($newsRow = mysql_fetch_assoc($sql_news))
{
$news[] = $newsRow;
}
return $news;
} // end news()
} // end Content
and it is called from index2.php like
$content_obj = new Content(); // call Content class
$category_data = $content_obj->newsCategory();
$smarty->assign("category",$category_data); // assign
$news_data = $content_obj->news($category_data);
$smarty->assign("news",$news_data); // assign
The above code executes without errors. The first three lines of index2.php above calls the class and calls the function newsCategory and passes the result into a SMARTY template file which works fine.
However, I want to pass the result of the first function call ( newsCategory() ) into the function news(). However the function news executes without printing anything to the screen. I can validate that all the SQL works as Ive hardcoded value replace
".$category_data."
with the expected result from the first function and everything prints to the screen as expected.
I've had all this code working procedureally but I want to streamline my code and lot more and have begun rewriting all the code. I'm obviously passing in the result from function newsCategory() to news() wrong and any advice to put it right would be appreciated.