Jump to content
Larry Ullman's Book Forums

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

Share this post


Link to post
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']. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...