Hi all,
i am having a problem setting up a connection to the database. up until now i have been using the built in Actions like the DB multi Record Loader to connect to the database. However now thing are geeting a bit more complicated i want to start using a custom code action and connect using code as i need to do a lot of manipulation of the data, running different queries depending on feedback from the form etc.
I have read a lot on how to do this. I am not a coder so this is all a learning curve for me. So i am going to need a few pointers as i go down this road🙂
I have a table in the database called hma_vehicles, and i want to select all the records belonging to the user.
I have the following code in a custom code action in the On_Load event of my form. and a debugger after the custom code, this shows nothing when i test the form, and nothing is loaded into the $form->data.
So what am i doing wrong here, is there a step i am missing before this? is the line
Thanks in advance
Allan
i am having a problem setting up a connection to the database. up until now i have been using the built in Actions like the DB multi Record Loader to connect to the database. However now thing are geeting a bit more complicated i want to start using a custom code action and connect using code as i need to do a lot of manipulation of the data, running different queries depending on feedback from the form etc.
I have read a lot on how to do this. I am not a coder so this is all a learning curve for me. So i am going to need a few pointers as i go down this road🙂
I have a table in the database called hma_vehicles, and i want to select all the records belonging to the user.
I have the following code in a custom code action in the On_Load event of my form. and a debugger after the custom code, this shows nothing when i test the form, and nothing is loaded into the $form->data.
<?php
$user = &JFactory::getUser();
$db =& JFactory::getDBO();
$query = "
SELECT 'vehicle_id', 'vrm'
FROM 'hma_vehicles'
WHERE 'user_id' = .$user->id
";
$db->setQuery($query);
$data = $db->loadAssocList();
$form->data = array_merge($form->data, $data) ;
?>
So what am i doing wrong here, is there a step i am missing before this? is the line
$db =& JFactory::getDBO();
all i need to open a connection to the Joomla! database (all my table are stored in the same DBThanks in advance
Allan