简体   繁体   中英

Create a new column in an array of data fetched from mysql table in php

$sqlfees = "SELECT feeid,occurence FROM feedetails WHERE applicablefor='$class'"; 
//fetching data
$fees_query = mysqli_query($db_conx, $sqlfees); 
//executing query
$count = mysqli_num_rows($fees_query);
if($count > 0) {
    while($fetch = mysqli_fetch_array($fees_query)) {
        $feesarr[] = $fetch; //creating array
}

I want to add a new column to $feesarr named 'dates' along with feeid and occurence with some values

Try something like this

     $sqlfees = "SELECT feeid,occurence FROM feedetails WHERE applicablefor='$class'"; 
     //fetching data
     $fees_query = mysqli_query($db_conx, $sqlfees); 
     //executing query
     $count = mysqli_num_rows($fees_query);
     if($count > 0) {
    while($fetch = mysqli_fetch_array($fees_query)) {
      $new_arr['date'] = $fetch['id'].'/'.other field what you want;
      $feesarr[] = array_merge($fetch, $new_arr); //creating array
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM