I have developped my own MVC component and I am almost there. I am a newbie with PHP and I am frankly a bit embarrassed to post my question for it is a basic programming question having to do with arrays, but I also know that I will learn from it.
This is my output in J!1.5 RC3. Notice that instead of showing the actual value of the element, the table shows the placeholder "array". (see image in attachement).
This is now my code of the fonction listing the articles in my ComponentName.php file. In this file, I push the query result ($rows) into the HTML class via the fonction showTable():
----------------------------------------------------------------------------------------
function listArtikelen() {
//was in book and does not work
//global $mainframe; //ori code of book.
//$db = &$mainframe->getDBO(); //ori code of book. Yields foutmelding at pageLoad
echo "My FE MVC component: DB queried for products
";
//Joomla framework knows which RDBMS sever and db to connect to: $db = 'joomlarc3'
//No need to use mysql_connect() and mysql_select_db() to tell him.
$db =& JFactory::getDBO() or die('Could select ('.$db.') : ' . mysql_error());
echo 'Step 1: Connected to DB successful!
';
// Performing SQL query
$query = "SELECT Artikel_Naam FROM jos_artikelen ";
$db->setQuery($query);
echo 'Step 2: Query executed successfully !
';
//(use code above) $rows = mysql_query($query) or die('Query failed: ' . mysql_error());
//Rows are returned?
if (!$result = $db->query()) {
echo $db->stderr();
}
//How many rows are returned?
$SQLresult = $db->getNumRows( $result );
echo ' Number of records found: ' .$SQLresult. '
';
//save array of db object in var $rows
$rows =& $db->loadObjectList();
//Class call to display $rows in HTML
HTML_artikelen::showTable($rows);
}
?>
-----
The second part of my MVC component is the HTML layout file, ComponentName.html.php . There is potentially my problem. It is like I am echoing on the string something that is an array but treating it differently in my code. I have tried to iterate using a foreach($rows as $keys => $values) but I got an error msg at parsing. Please help!
|
} //end function
} //end class
-----