After some investigation I find out that my select should be able to do this:
we have 2 tables
jos_polls
jos_poll_data
from the 1st table
jos_polls we must select rows where
published="1"
and in the same tame in the 2nd table
jos_poll_data is
pollid equal to
id from the first
jos_polls table
How will this code look like when we want to do the above stuff?
class modPollHelper
{
function getPoll($id)
{
$db =& JFactory::getDBO();
$result = null;
$query =
'SELECT id, title,'
.' CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(\':\', id, alias) ELSE id END as slug '
.' FROM #__polls'
.' WHERE id = '.(int) $id
.' AND published = 1'
;
$db->setQuery($query);
$result = $db->loadObject();
if ($db->getErrorNum()) {
JError::raiseWarning( 500, $db->stderr() );
}
return $result;
}
function getPollOptions($id)
{
$db =& JFactory::getDBO();
$query = 'SELECT id, text' .
' FROM #__poll_data' .
' WHERE pollid = ' . (int) $id .
' AND text <> ""' .
' ORDER BY id';
$db->setQuery($query);
if (!($options = $db->loadObjectList())) {
echo "MD ".$db->stderr();
return;
}
return $options;
}
}
?>