1

I have a static array like this.

$row = array($aRow['colum_name_1'],$aRow['colum_name_2'],$aRow['colum_name_3']);

I want store my data using while loop in php for dynamic column in array

This is my code:

while ($aRow = $rResult->fetch_assoc()) 
        {
$data = "";
$data_cus_dt1 = mysqli_query($con,"select column_name from custom_table_column");
            while($my_cus_dt=mysqli_fetch_object($data_cus_dt1))
            {
                $mydata = $my_cus_dt->column_name; 
                $data  .= $aRow[$mydata].",";
            }   
   $row = array($data);
}

I want to result dynamic column, like static array.

$row = array($aRow['colum_name_1'],$aRow['colum_name_2'],$aRow['colum_name_3']);

1 Answer 1

1

There's no point using $data variable in your code, that too as a string. You can directly use the $row array(initially empty) in the inner while() loop to get the resultant array.

$row = array();
while ($aRow = $rResult->fetch_assoc()){
    $data_cus_dt1 = mysqli_query($con,"select column_name from custom_table_column");
    while($my_cus_dt=mysqli_fetch_object($data_cus_dt1)){
        $row[] = $aRow[$my_cus_dt->column_name]; 
    }   
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.