PHP的未定义变量和试图获取非对象属性的通知
作者:互联网
我正在学习通过在Joomla项目上执行php
如何改进此代码和解决PHP公告-任何建议-解决方案-非常感谢!
注意:未定义的变量:在第140行的* / home / mygames / public_html / components / com_toys / models / category.php中
(这是$sql行)*
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";
注意:试图在第200行的/home/truecar7/public_html/components/com_toys/models/category.php中获取非对象的属性
第200行是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;
}
编辑
你好罗德& Elin,它起作用了,但是像这样,否则它在return $row行上显示了未定义的变量通知.
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;
}
解决方法:
尝试使用以下内容.我对您的功能进行了一些更改,并使用Joomla 2.5编码标准进行数据库查询.
$Name = "XXXXXXXXX"; //define the name variable
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;
}
return $row;
}
echo getItemIdByName($Name); //echo the result of the function
标签:joomla2-5,joomla,php 来源: https://codeday.me/bug/20191030/1968383.html