Jump to content

Get 'proper' array from sql result


Recommended Posts

$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

Link to post
Share on other sites

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?

Link to post
Share on other sites
Posted (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 by Barand
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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.