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