I'm loading values from a custom category table in Joomla 2.5. This works fine, I can display the name for each category.
Then I want to add categories with a specific id to a new array, but I can't make it work. In C# i know exactly how to do this, but not in PHP.
Here's my code (thx for fixing the code format):
<?php
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query->select('*');
$query->from('ind_category');
$query->order('Name ASC');
echo $query . "</br>";
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$categories = $db->loadObjectList();
// show the retrieved categories
if ($categories != null) {
foreach ($categories as $cat) {
echo "Name: " . $cat->Name . "</br>";
}
} else {
echo "<br> NULL results from " . $query;
}
echo "<br>";
echo "<br>";
// add objects from $categories with specific Id to $arr2
$arr2 = array();
foreach ($categories as $cat) {
if ($cat->Id == 1) {
$arr2[] = $cat;
}
}
?>