How to store row/column of mysql data in array

后端 未结 2 1757
孤街浪徒
孤街浪徒 2021-01-12 15:10

I want to be able to store (not echo) some data that has been selected from a mysql database in a php array. So far, I have only been able to echo the information, I just wa

2条回答
  •  借酒劲吻你
    2021-01-12 16:02

    You can "store" it by not accessing it from the result set until you need it, but if you really want to just take it and put it in a variable…

    $query = "SELECT interests FROM signup WHERE username = '$username'";
    $result = mysql_query($query) or die ("no query");
    
    $interests = array();
    while(false !== ($row = mysql_fetch_assoc($result))) {
      $interests[] = $row;
    }
    

提交回复
热议问题