search

Home  >  Q&A  >  body text

How to implement multi-level associated multi-dimensional arrays in PHP and Mysql?

< /p>

As shown in the figure, a User has multiple topics, and each topic has a corresponding theme.

Please tell me how to implement this relationship using php+mysql?

黄舟黄舟2811 days ago309

reply all(2)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:05:29

    Do you mean the actual table structure, or how to query this data form

    I don’t know if you wrote it in a framework or natively

    // 查詢USER表
    $returndata = array();
    while($userdata = mysql_fetch_assoc()) {
       
        $id = $userdata['id'];
        //跟著根據id查詢topics
        $topicssql = "";
        .....
        $userdata['topics'] = array();
        while($topicsd = mysql_fetch_assoc()) {
            $userdata['topics'][] = $topicsd; 
        }
    }
    
    

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:05:29

    This is usually done by merging the retrieved data in the background

    reply
    0
  • Cancelreply