-1

所有这一切的最终结果应该是应该填充用于描述和传递的数组,并且我应该能够回应它们。但是,只有描述会回显,而密码不会回显。从我的所有测试来看,对于 result1 查询,$value 变量似乎是空的。我不知道如何在第二个查询中使用 $value。

我也收到这两个错误:注意:未定义的变量:在第 60 行传入 /var/www/html/manage/commit.php 警告:在 /var/www/html/manage/commit 中为 foreach() 提供的参数无效。第 60 行的 php

// From manage.phones
$result = mysqli_query($con_manage,"SELECT * FROM phones");
while($row = mysqli_fetch_array($result))
{
    $mac[] = $row['mac'];
    $mapped_to[] = $row['mapped_to'];
}

// From asterisk.devices
foreach($mapped_to as $value)
{
  $result = mysqli_query($con_asterisk,"SELECT description as description FROM devices WHERE id='$value'");
  while($row = mysqli_fetch_array($result))
  {
    $description[] = $row['description'];
  }
  $result1 = mysqli_query($con_asterisk,"SELECT data as data FROM sip WHERE id='$value'");
  while($row = mysqli_fetch_array($result))
  {
    $pass[] = $row['data'];
  }

}

// Echo the descriptions and passwds!
echo "Echo all descriptions:";
echo"\n";
foreach($description as $key => $value)
{
  echo "$value\n";
}

echo "Echo all passwds:";
echo"\n";
foreach($pass as $key => $value)
{
  echo "$value\n";
}
4

3 回答 3

0

查询的SELECT data as data FROM sip WHERE id='$value'结果集为空。这就是为什么$pass[] = $row['data']永远不会被执行。因为您没有$pass明确定义(例如,$pass = array()在您的第一个foreach循环之前),所以在尝试foreach($pass as $key => $value).

于 2013-08-07T20:29:19.647 回答
0

你应该添加

$pass = array();

在 foreach 循环之前

// From asterisk.devices
foreach($mapped_to as $value) { .... }
于 2013-08-07T20:30:03.410 回答
0

改变

$result1 = mysqli_query($con_asterisk,"SELECT data as data FROM sip WHERE id='$value'");

$result1 = mysqli_query($con_asterisk,"SELECT data as data FROM sip WHERE id='".$value."'");.

你应该对你的两个查询都这样做。这就是连接字符串的方式。你的回声也一样

填充你的数组,你应该做

$description = array(); //initialize your array
while($row = mysqli_fetch_array($result))
{
   array_push($description, $row['description'];
}

对 $pass 做同样的事情

于 2013-08-07T20:41:32.887 回答