i'm trying to create a joomla component. The component is about generating a sentence. Basicly, here's the code/function that will help me generate it.
function getCategory()
{
$cat = array("walk","reside","eat");
return $b = $cat[array_rand($cat)];
}
function getS1() //function 1.1
{
$db = JFactory::getDBO();
$query = "select words from #__wordbank where function = 1.1 order by rand() LIMIT 1";
$db->setQuery($query);
return $db->loadResult();
}
function getV11() //function 2.11
{
$db = JFactory::getDBO();
$b = getCategory();
$query = "select words from #__wordbank where function = 2.11 AND category = '$b' order by rand() LIMIT 1";
$db->setQuery($query);
return $db->loadResult();
}
function getP1() //function p1.1
{
//load preposition
$db = JFactory::getDBO();
$b = getCategory();
$query = "select words from #__wordbank where function = 'p1.1' AND category = '$b' order by rand() LIMIT 1";
$db->setQuery($query);
return $db->loadResult();
}
function getP2() //function p1.2
{
//load noun
$db = JFactory::getDBO();
$b = getCategory();
$query = "select words from #__wordbank where function = 'p1.2' AND category = '$b' order by RAND() limit 1";
$db->setQuery($query);
return $db->loadResult();
}
the problem is when i getCategory()
the return value is always different. I try to use if else but still it return different value because of $cat[array_rand($cat)]
. Would appreciate if you guys could help me solve this bug