Am learning & executing php by working on Joomla project How to Improve this code & resolve the PHP Notices - Any suggestions - solutions - well appreciated !!
Notice: Undefined variable: cond in*/home/mygames/public_html/components/com_toys/models/category.php on line 140 (which is $sql line)*
function loadSubCat($id,$Carmodel,$minprice,$maxprice){
$mainframe =& JFactory::getApplication();
$option = JRequest::getCmd('option');
$database =& JFactory::getDBO();
global $Itemid;
if($Carmodel!="")
$cond=" and prod_id='$Carmodel' ";
$sql = "Select * from #__toycar_products Where prod_cat_id='".$id."' $cond and prod_status='1' and prod_id in (select v_prod_id from #__toycar_variants) Order By prod_sorder";
Notice: Trying to get property of non-object in /home/truecar7/public_html/components/com_toys/models/category.php on line 200
Line 200 is return $row->id;
function getItemIdByName($Name){
$mainframe =& JFactory::getApplication();
$option = JRequest::getCmd('option');
$database =& JFactory::getDBO();
$sql = "Select id from #__menu Where name = '".$Name."'";
$database->setQuery($sql);
$row = $database->loadObject();
return $row->id;
}
Edit
Hello Lodder & Elin, it works but like this, else it's showing undefined variable notice for row on return $row line.
function getItemIdByName($Name){
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')
->from('#__menu')
->where('id = ' . $db->quote($Name));
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row){
$row = $row->msg;
}
$row='';
return $row;
}