由于某种原因$ Value会抛出此错误(是的,我确信这一点,如果我从查询中删除它,则不会抛出错误 - 显然这会使代码无用,如果我尝试分配$值之前它还会引发错误)。
array(2){[0] => object(stdClass)#1(1){["插件ID"] =>字符串(1)" 2" } [1] => object(stdClass)#2(1){["插件ID"] =>字符串(1)" 3" }}
$PLChecked = [];
foreach ($a as $b){
$checkNum = $;
$result = mysql_query("Select `cc` FROM `aa` WHERE `Checksum` LIKE '$checkNum'");
if (mysql_num_rows($result) == 1){
$result = mysql_query("SELECT `ID` FROM `aa` WHERE `cc` LIKE '$checkNum' LIMIT 1");
$value = mysql_fetch_object($result); //here i would like to get the selected ID
$PLChecked[] = $value;
}
}
foreach ($PLChecked as $Value)
{
//$a;
$sqlano = "SELECT `Link` FROM `aa` WHERE `ID`LIKE '$Value'"; // This throws the error -- or at least that's what php says.
//$resultawqe = mysql_query($sqlano);
//$value = mysql_fetch_row(mysql_query($sqlano));
//$PLLinks[] = $resultawqe;
}
现在,我在代码的另一部分中有这个确切的代码,它运行正常(实际上查询略有不同,但它基本上是相同的)。 我不知道为什么会这样做。
顺便说一句,如果它的内容很容易修复,请发一个提示作为答案,稍后,当选择正确时,您可以添加实际修复。
感谢
答案 0 :(得分:0)
使用foreach循环添加到PLChecked数组的值应为“string”类型。 添加到PLChecked应该像$ PLChecked [] = $ value-> ID而不是$ PLChecked [] = $ value;因为$ value是一个对象,它包含您从查询中选择的ID。
答案 1 :(得分:0)
可能你正在寻找这个。
if (mysql_num_rows($result) == 1){
$result = mysql_query("SELECT `ID` FROM `aa` WHERE `cc` LIKE '$checkNum' LIMIT 1");
$value = mysql_fetch_object($result); //here i would like to get the selected ID
// if $value is object or array then you will loop through it like
foreach($value as $val){
$PLChecked[] = $val->ID; in case of object
$PLChecked[] = $val['ID']; in case of array
}
}
foreach ($PLChecked as $Value)
{
// now variable $value will contain ID and the below query will work.
$sqlano = "SELECT `Link` FROM `aa` WHERE `ID`LIKE '$Value'";
}