多维数组错误的PHP表显示

多维数组错误的PHP表显示,php,html,arrays,echo,Php,Html,Arrays,Echo,我正在尝试显示此查询的输出: $resultReturn = $con->prepare( "SELECT `returns`.`return_id`, `returns`.`return_ZDTicket`, status.status_description, orders.customer_email\n" . "FROM `returns` \n" . " LEFT JOIN `status` ON `re

我正在尝试显示此查询的输出:

  $resultReturn = $con->prepare( "SELECT `returns`.`return_id`, `returns`.`return_ZDTicket`,  status.status_description, orders.customer_email\n"

    . "FROM `returns` \n"

    . " LEFT JOIN `status` ON `returns`.`return_status` = `status`.`status_id`\n"

    . "    LEFT JOIN `agents` ON `returns`.`agent_id` = `agents`.`id`\n"

    . "    LEFT JOIN `orders` ON `returns`.`return_orderID` = `orders`.`order_id`\n"

    . "WHERE `agents`.`id` = ? ");


$resultReturn->bind_param('i', $id);
$resultReturn->execute();
$resultReturn->store_result();
$resultReturn->bind_result($returnID, $returnZD, $returnStatus,$returnCustomerEmail);


$arrayReturnID[] = array();
$arrayreturnZD[] = array();
$arrayreturnStatus[] = array();
$arrayreturnCustomerEmail[] = array();

while ($resultReturn->fetch()){
    array_push($arrayReturnID,$returnID);
    array_push($arrayreturnZD,$returnZD);
    array_push($arrayreturnStatus,$returnStatus);
    array_push($arrayreturnCustomerEmail,$returnCustomerEmail);

}

array_splice($arrayReturnID, 0, 1);
array_splice($arrayreturnZD, 0, 1);
array_splice($arrayreturnStatus, 0, 1);
array_splice($arrayreturnCustomerEmail, 0, 1);

$returnsTable = array($arrayReturnID,$arrayreturnZD,$arrayreturnStatus,$arrayreturnCustomerEmail);
如果我们打印$returnsTable,结果如下:

Array ( [0] => Array ( [0] => 2 ) [1] => Array ( [0] => 268903 ) [2] => Array ( [0] => OPEN ) [3] => Array ( [0] => mariorossi@testnetatmo.com ) )
这是我的桌子:


返回ID
ZD票
返回状态
客户电子邮件

你能帮我展示一下桌子吗?这让我抓狂,php不是我的拿手好戏(谢谢!

我会放弃4个
数组拼接
调用,而只取每个数组的第一个元素:

$returnsTable = array($arrayReturnID[0],$arrayreturnZD[0],$arrayreturnStatus[0],$arrayreturnCustomerEmail[0]);
这将使
$returnsTable
成为一个简单的数组,您可以使用一个简单的foreach循环:

          <tbody>
          <tr>
              <th>Return ID</th>
              <th>ZD Ticket</th>
              <th>Return Status</th>
              <th>Customer Email</th>
          </tr>
          <tr>
              <?php 
              foreach($returnsTable as $item){
                  echo "<td>".$item."</td>";
              }
              ?>
          </tr>
          </tbody>
          </table>
      </div>

返回ID
ZD票
返回状态
客户电子邮件

假设,根据您的问题:“我正在尝试显示此查询的输出”

…并且您希望返回查询的全部内容(否则您应该缩小查询范围)。您不需要使用数组函数不断移动数据,只需输出数据即可

当前,您的代码没有添加任何
HTML
标记来显示输出

<?

 $resultReturn = $con->prepare("
    SELECT 
        `returns`.`return_id`, `returns`.`return_ZDTicket`,
        `status`.`status_description`, `orders`.`customer_email`
    FROM `returns`
        LEFT JOIN `status` ON `returns`.`return_status` = `status`.`status_id`
        LEFT JOIN `agents` ON `returns`.`agent_id` = `agents`.`id`
        LEFT JOIN `orders` ON `returns`.`return_orderID` = `orders`.`order_id`
    WHERE `agents`.`id` = ? ");


$resultReturn->bind_param('i', $id);
$resultReturn->execute();
$resultReturn->store_result();
$resultReturn->bind_result($returnID, $returnZD, $returnStatus,$returnCustomerEmail);

$returnTable = "";                                     // Initialise output variable
while ($resultReturn->fetch()){                        // Loop through results
    $returnTable .= "<tr>";                            // Start a new table row
    $returnTable .= "<td>{$returnID}</td>";            // Return table data in a cell
    $returnTable .= "<td>{$returnZD}</td>";            // ^^
    $returnTable .= "<td>{$returnStatus}</td>";        // ^^
    $returnTable .= "<td>{$returnCustomerEmail}</td>"; // ^^
    $returnTable .= "</tr>";                           // End table row
}

?>

          <tbody>
          <tr>
              <th>Return ID</th>
              <th>ZD Ticket</th>
              <th>Return Status</th>
              <th>Customer Email</th>
          </tr>
              <?php  echo $returnTable; ?>              // Print table content to page
          </tbody>
          </table>
      </div>

返回ID
ZD票
返回状态
客户电子邮件
//将表格内容打印到页面

问题是,当我使用array\u push时,它会将数组中的元素按索引0+1推送,因此0始终为空。然后一个简单的解决方案是保留4 arry\u拼接,然后使用我显示的0索引生成$returnsTable数组,而不是使用整个数组
<?

 $resultReturn = $con->prepare("
    SELECT 
        `returns`.`return_id`, `returns`.`return_ZDTicket`,
        `status`.`status_description`, `orders`.`customer_email`
    FROM `returns`
        LEFT JOIN `status` ON `returns`.`return_status` = `status`.`status_id`
        LEFT JOIN `agents` ON `returns`.`agent_id` = `agents`.`id`
        LEFT JOIN `orders` ON `returns`.`return_orderID` = `orders`.`order_id`
    WHERE `agents`.`id` = ? ");


$resultReturn->bind_param('i', $id);
$resultReturn->execute();
$resultReturn->store_result();
$resultReturn->bind_result($returnID, $returnZD, $returnStatus,$returnCustomerEmail);

$returnTable = "";                                     // Initialise output variable
while ($resultReturn->fetch()){                        // Loop through results
    $returnTable .= "<tr>";                            // Start a new table row
    $returnTable .= "<td>{$returnID}</td>";            // Return table data in a cell
    $returnTable .= "<td>{$returnZD}</td>";            // ^^
    $returnTable .= "<td>{$returnStatus}</td>";        // ^^
    $returnTable .= "<td>{$returnCustomerEmail}</td>"; // ^^
    $returnTable .= "</tr>";                           // End table row
}

?>

          <tbody>
          <tr>
              <th>Return ID</th>
              <th>ZD Ticket</th>
              <th>Return Status</th>
              <th>Customer Email</th>
          </tr>
              <?php  echo $returnTable; ?>              // Print table content to page
          </tbody>
          </table>
      </div>