In my Joomla component I have two table:
Table1: #__com_units
Id | unit | posx | posy
------------------------
1 | 001A | 100 | 200
2 | 002A | 101 | 202
3 | 003A | 102 | 204
4 | 004A | 103 | 206
5 | 005A | 104 | 208
Table1: #__com_reservations
Id | unit | From | To | Mood (dropdown with value of Avaliable and Rented)
--------------------------------------------
1 | 001A | YYYY-MM-DD | YYYY-MM-DD |Available
2 | 002A | YYYY-MM-DD | YYYY-MM-DD |Rented
3 | 003A | YYYY-MM-DD | YYYY-MM-DD |Available
3 | 004A | YYYY-MM-DD | YYYY-MM-DD |Available
3 | 005A | YYYY-MM-DD | YYYY-MM-DD |Rented
i want two get two query to show the result as buttons, but its not working:
1) One for Rented units
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$jinput = JFactory::getApplication()->input;
$query->select($db->quoteName(array('id', 'unit', 'mood', 'posx', 'posy')));
$query->from($db->quoteName('#__com_units', '#__com_reservations'));
$query->where($db->quoteName('unit')." = ".$db->quote('1'),'AND')
->where($db->quoteName('mood')." = ".$db->quote('rented'));
$db->setQuery($query);
$results = $db->loadObjectList();
foreach ($results as $result)
{
echo '<button class=" ' . $result->mood . ' ' . $result->posx . ' ' . $result->posy . '" value=' . $result->id . ' disabled> ' . $result->unit . '</button>';
}
2)One for Avaliable units
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$jinput = JFactory::getApplication()->input;
$query->select($db->quoteName(array('id', 'unit', 'mood', 'posx', 'posy')));
$query->from($db->quoteName('#__com_units', '#__com_reservations'));
$query->where($db->quoteName('unit')." = ".$db->quote('1'),'AND')
->where($db->quoteName('mood')." = ".$db->quote('available'));
$db->setQuery($query);
$results = $db->loadObjectList();
foreach ($results as $result)
{
echo '<button class=" ' . $result->mood . ' ' . $result->posx . ' ' . $result->posy . '" value=' . $result->id . ' disabled> ' . $result->Unit . '</button>';
}
3)And what if i want to have one query for rented units when they have valid date range?