MyBB-Plugins Forums
$db->fetch_array only showing one array - Printable Version

+- MyBB-Plugins Forums (http://forums.mybb-plugins.com)
+-- Forum: MyBB General Discussion (http://forums.mybb-plugins.com/Forum-MyBB-General-Discussion)
+--- Forum: Coding Help (http://forums.mybb-plugins.com/Forum-Coding-Help)
+--- Thread: $db->fetch_array only showing one array (/Thread-db-fetch-array-only-showing-one-array)



$db->fetch_array only showing one array - Cyberuben - 12-01-2012

Hey,

Currently I'm trying to use the following code to put out ALL entries in a certain database (within the "WHERE"). The problem is that it only puts out one value, one array, while I want it to return multiple arrays, with an array in it containing data as "uid", "name", etc.

I'm using the following code:
PHP Code:
function list_entries($raffle_start$raffle_end) {
        global 
$db;
        
        
$sql 
            
"
            SELECT
                *
            FROM
                <prefix removed>_raffle_entries
            WHERE
                time > "
.$raffle_start."
            AND
                time < "
.$raffle_end."
            LIMIT 5"
            
;
            
        
$query $db->query($sql);
        
$entries = array();
        while(
$records $db->fetch_array($query)) {
            
$entries[] = $records;
        }

        return 
$entries;
    } 

It doesn't seem to work, atleast, it only returns one array:
Code:
Array (
[uid] => 1
[name] => Ruben
[time] => 1354366024
)
It should return:
Code:
Array (
[1] => Array (
[uid] => 1
[name] => Ruben
[time] => 1354366024  
)
[2] => Array (
[uid] => 2
[name] => Jordan
[time] => 1354366510
)
)
I'm sure these values exist in the database.

EDIT:
Fixed it, forgot to put $records = array(), but after I put that, refreshed the page, and then removed that line again, to show my dad what was wrong (I talk with him a lot about PHP), it still worked. Strange.


RE: $db->fetch_array only showing one array - Omar G. - 12-02-2012

I see no reason for it to fail, may be you didn't save the file? Tongue Happens sometimes to me, editing a different file or not saving them..


RE: $db->fetch_array only showing one array - Cyberuben - 12-02-2012

I did save the file multiple times. But my dreamweaver acts up once now and then.


RE: $db->fetch_array only showing one array - Omar G. - 12-02-2012

Use some advance text editor, something like Notepadd++.


RE: $db->fetch_array only showing one array - Cyberuben - 12-02-2012

I rather use Dreamweaver because it is more than just text.


RE: $db->fetch_array only showing one array - Omar G. - 12-03-2012

Well, if you are writing MyBB friendly code then you shouldn't be using Dreamweaver, it doesn't work like that (again, if you are writing friendly code, i.e: You plan to release a plugin that is well written).


RE: $db->fetch_array only showing one array - Cyberuben - 12-03-2012

What's the problem with Dreamweaver then?


RE: $db->fetch_array only showing one array - Diogo Parrinha - 12-03-2012

Most people use DW because it generates HTML code. If you are writing plugins there is no point in using it, you need to stick to the templates.


RE: $db->fetch_array only showing one array - Cyberuben - 12-04-2012

I'm just using it because I find it more useful than Notepad++ for HTML.