Mysql
 sql >> Database >  >> RDS >> Mysql

istruzione select restituisce sempre l'ultima riga inserita in php mysql

        if (mysql_num_rows($result) > 0) {
        $result = mysql_fetch_array($result);

        $product = array();
        $product["name"] = $result["name"];
        $product["unit"] = $result["unit"];
        $product["calory"] = $result["calory"];
        $product["carbohydrate"] = $result["carbohydrate"];
        $product["category"] = $result["category"];


        // success
        $response["success"] = 1;

        // user node
        $response["product"] = array();

        array_push($response["product"], $product);

        // echoing JSON response
        echo json_encode($response);
    }

sostituiscilo con

while(mysql_num_rows($result) > 0 && ($result = mysql_fetch_array($result))) {

        $product = array();
        $product["name"] = $result["name"];
        $product["unit"] = $result["unit"];
        $product["calory"] = $result["calory"];
        $product["carbohydrate"] = $result["carbohydrate"];
        $product["category"] = $result["category"];


        // success
        $response["success"] = 1;

        // user node
        $response["product"] = array();

        array_push($response["product"], $product);

        // echoing JSON response
        echo json_encode($response);
    }

il risultato è un array e non stai scorrendo in loop, quindi fornisce solo un elemento nell'array