Minzer Posted May 1, 2021 Share Posted May 1, 2021 $sql = "SELECT option_id, id FROM bets WHERE win_status = '1' AND updated_at BETWEEN '$today 13:00:00.000000' AND '$tmrw 08:00:00.000000'"; $result = mysqli_query($connt, $sql); foreach($result as $value) { $value[] = arary_multisort(); $oid = $value['option_id']; $gid = $value['id']; var_dump($value); //$gim = var_export($value); } foreach($result as $key => $value) { $info = array($value); } mysqli_close($connt); $fl = array($oid, $gid); print_r($fl); array ( 'option_id' => 'game1a', 'id' => '155670450', )array ( 'option_id' => 'game2h', 'id' => '386887537', Either I can return 1 row and have the data sorted nicely or I can return an array but I can only seem to access the last array. Been stuck on this bit for atleast 2 hrs sadly. How can I rename the array? Some days I might have 100 results. Today we have two winners xP I really need to ctrl+z sublime cuz I tried what feels like everything. Ancy to move to the next part of this code MATH if you can kindly assist. Yall have been extremely helpful in my last two posts 2/2 going on 3. Is there a place I can properly contribute lite silver :3 Quote Link to comment https://forums.phpfreaks.com/topic/312575-get-proper-array-from-sql-result/ Share on other sites More sharing options...
maxxd Posted May 1, 2021 Share Posted May 1, 2021 I'm not entirely sure what you're trying to accomplish with everything after the mysqli_query (also, you may want to look into PDO as it's much easier), but what does this give you: die("<pre>".var_export($result, true)."</pre>"); if you put it right after the mysqli_query line? Quote Link to comment https://forums.phpfreaks.com/topic/312575-get-proper-array-from-sql-result/#findComment-1586271 Share on other sites More sharing options...
Barand Posted May 1, 2021 Share Posted May 1, 2021 (edited) What does your function arary_multisort() do? Are you wanting something like this (sorting them in the query) ... $res = $conn->query("SELECT option_id , id FROM bets WHERE win_status = '1' AND updated_at BETWEEN '2021-05-01 13:00:00.000000' AND '2021-05-02 08:00:00.000000' ORDER BY option_id, id "); $info = []; foreach ($res as $row) { $info[$row['option_id']][] = $row['id']; } echo '<pre>', print_r($info, 1), '</pre>'; giving Array ( [game1a] => Array ( [0] => 255670450 [1] => 255670900 [2] => 455670450 ) [game2h] => Array ( [0] => 126887550 [1] => 386887537 [2] => 486887537 ) ) Edited May 1, 2021 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/312575-get-proper-array-from-sql-result/#findComment-1586275 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.