• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Syntax for conditional query dropdownbox

Syntax for conditional query dropdownbox 6 years 6 months ago #38552

  • willem51
  • willem51's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Hi,

On a form I would like to populate a dropdownbox from a table. The items are depending on which user is logged in.
The query works fine when I 'hardcode' the users ID. I would like to use the ID from the user. What is the right syntax for the user in the code here below? Look for 971.

Kind regards,
Willem
//<code>
//identify user
$user = JFactory::getUser();
 
// Prepare the empty array
$items = array();
// Prepare the database connection
$db = JFactory::getDbo();
// Keep this if you'd like a "Please select" option, otherwise comment or remove it
$items[] = "|Please Select[c]";
 
// Run the SQL query and store it in $results
$db->setQuery("SELECT equipment_type , equipment_detail   FROM zbw_speed_equipment  where equipment_userid = '971'");
$results = $db->loadObjectList();
 
// Now, we need to convert the results into a readable RSForm! Pro format.
// The Items field will accept values in this format:
// value-to-be-stored|value-to-be-shown
// Eg. m|M-sized T-shirt
foreach ($results as $result) {
  $value = $result->equipment_type;
  $label = $result->equipment_detail;
  $items[] = $value.'|'.$label;
}
 
// Multiple values are separated by new lines, so we need to do this now
$items = implode("\n", $items);
 
// Now we need to return the value to the field
return $items;
//</code>
The administrator has disabled public write access.

Syntax for conditional query dropdownbox 6 years 6 months ago #38556

  • willem51
  • willem51's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Problem solved! B)

Modified the code to this:
$db->setQuery("SELECT equipment_type , equipment_detail   FROM zbw_speed_equipment  where equipment_type = 'board' AND equipment_username =  '$user->username'");
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!