For each result in MySQL query, push to array (complicated)

后端 未结 3 1186
感情败类
感情败类 2021-01-29 00:45

Okay, here\'s what I\'m trying to do. I am running a MySQL query for the most recent posts. For each of the returned rows, I need to push the ID of the row to an array, then wit

3条回答
  •  -上瘾入骨i
    2021-01-29 01:04

        $master[$id]['post_title'] = $post_title;
        $master[$id]['post_text'] = $post_text;
        // etc
    

    or, less code. With this one, you can get rid of where you set all those variables:

        $master[$row["id"]]['post_title'] = $row["title"];
        $master[$row["id"]]['post_text'] = $row["text"];
        // etc
    

    Edit in answer to comment:

    foreach( $master as $row )
    {
        echo $row['post_title'];
    }
    
    // or if you know the id
    
    echo $row[$id]['post_title'];
    

提交回复
热议问题