Array_push只返回最后一个被压入的元素


array_push only returns the last element pushed in?

$orders变量只返回数组中最后一个被压入的元素,而不是返回所有元素。我确实使用了array_push将元素压入数组$orders但我只得到最后一个元素压入…

// Create arrays to populate so that I can iterate over them to display the data on the charts
 $views = array();
 $orders = array();
if ($pid == 11 && $value > 1631 && $value <= 1635) {
    $query = "SELECT label, hits FROM items WHERE item_id='$value' LIMIT 1";
    $result = mysql_query($query);
    $row = mysql_fetch_assoc($result);
    echo "<td>" . $row['label'] . "</td>";

    // orders
    if ($row['hits'] != 0) {
        echo "<td>" . $row['hits'] . "</td>"; 
    }else{
        echo "<td>0</td>";
    }
} else {
    $query = "SELECT label FROM items WHERE item_id='$value' LIMIT 1"; 
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)){
    echo "<td>" . strip_tags(DecodeSpecialChars(html_entity_decode($row['label']))) . "</td>"; 
    if(array_key_exists('label',$row)) {
     array_push($orders,$row['label']); // pushing here ..
    }

    if ($pid != 58) {
        // orders
        if (isset($totals[$value]) && $totals[$value] != 0) { 
            echo "<td>" . $totals[$value] . "</td>"; 

        }else{
            echo "<td> 0 </td>";
        }
    }
}
var_dump($orders);

您的查询上有limit 1子句…push

只会得到一个结果