0

我有一个多维数组,我无法更新其中之一:

public function get_list($query){
    if(mysql_query($query,DB::connect())){
       $result = mysql_query($query);
       if (mysql_affected_rows() != 0) {
           while ($row = mysql_fetch_array($result)) {
            $list_annunci[] = array(
              "id" => $row["id"],
              "title" => $row["title"]
            );
            if(mysql_query($immagini,DB::connect())){
            $result_img = mysql_query($immagini);
                if (mysql_affected_rows() != 0) {
                   while ($row_img = mysql_fetch_array($result_img)) {
                        $list_annunci[] = array(
                          "img" => $row_img["path_img"]
                        );
                   }
                }
           }
        }

如何在已声明的数组中插入记录?tnx stefania

4

1 回答 1

0

Use your ids as keys for the original array.

$list_annunci[$id] = array(

Make the database query returns those ids as well.

SELECT id, path_img

Then you can inject or update the right group.

$list_annunci[  $id  ]["img"] = $row_img["path_img"];
                 ^
                 |
         from $row_img["id"]
于 2013-07-07T14:52:39.160 回答