My database Front-end component. Almost there. Please Help!

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
User avatar
cgiguere
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Mon Sep 17, 2007 9:21 am

My database Front-end component. Almost there. Please Help!

Post by cgiguere » Mon Jan 07, 2008 4:43 pm

Hello guys,

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!









Let's fetch the data now...
  //select each row of the dataset
$key=0;
    foreach($rows as $row ) {  ?>


} //end for each
?>







} //end function

} //end class

-----
Attachments
FEcomponent_Output.JPG

mike_dowler
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Mon Nov 06, 2006 11:03 pm
Location: Birmingham, UK

Re: My database Front-end component. Almost there. Please Help!

Post by mike_dowler » Tue Jan 22, 2008 9:57 pm

I can't be entirely sure, but I think the problem is that you are obtaining your db results as objects, rather than as arrays.

I think you want to use loadAssocList rather than loadObjectList (towards the end of your first function).

Let me know how you get on.

User avatar
cgiguere
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Mon Sep 17, 2007 9:21 am

Re: My database Front-end component. Almost there. Please Help!

Post by cgiguere » Sat Jan 26, 2008 10:04 am

I tried your recommendation and unfortunately, it is still give me the same result.
If you have any other suggestions, more than happy to hear them.
Thanks!

radiant_tech
Joomla! Apprentice
Joomla! Apprentice
Posts: 41
Joined: Sat Dec 15, 2007 3:02 pm
Location: Washington DC Metro

Re: My database Front-end component. Almost there. Please Help!

Post by radiant_tech » Sun Jan 27, 2008 12:25 pm



Notice also that in your code above you are using the plural form of $rows within your foreach statement -- instead it would need to be $row
Denise


Post Reply