Jump to content
Larry Ullman's Book Forums

How can I add mysqli result set to another array


Recommended Posts

Am trying to put mysqli result set into an array for later use and this is how I did it(but is not working)

$split = [];
$sql_money = "SELECT j_id, amount_invested FROM j_members WHERE j_activated = 1 LIMIT 5";
$result_money = mysqli_query($conn, $sql_money);
while($data = mysqli_fetch_assoc($result_money)){
$split[] = ['id' => $data['id'], 'invest' => $data['amount_invested']];
//echo $data['j_id'];
}

foreach($split as $s){
echo $s['id'] . '<br>';
}
Who can put me through

Link to comment
Share on other sites

This should do it:

$sql_money = "SELECT j_id, amount_invested FROM j_members WHERE j_activated = 1 LIMIT 5";
$result_money = mysqli_query($conn, $sql_money);
$split = mysqli_fetch_all($result_money, MYSQLI_ASSOC);

Yours wasn't working, by the way, because the query selects j_id and your code refers to $data['id']. 

Link to comment
Share on other sites

 Share

×
×
  • Create New...