array_push只返回推入的最后一个元素?

时间:2013-05-20 21:10:30

标签: php php-5.3

$ orders变量只返回数组的最后一个推送元素,而不是返回所有元素..我确实使用array_push将元素推送到数组$ orders但是我只获得推送的最后一个元素... < / p>

// 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);

1 个答案:

答案 0 :(得分:5)

您的查询中有limit 1条款......您只能获得一个推送结果