Jump to content

getting array from table


Dragen

Recommended Posts

um..

Shouldn't

mysql_fetch_assoc($res))

be

mysql_fetch_array($res))

??

 

Also, I'm sure I'm just being stupid here, but it brings up a blank screen which I presume is because I'm not echoing it.

So I tried to echo by using:

while ($row = mysql_fetch_assoc($res)) {
       $booked[] = $row;
       echo $booked;
}

but that just repeated the words 'array' three times. The same amount of entries in the table..

As I said, I'm sure it's just me being silly..

okay thanks.

When I change it to print with the <pre> attribute it displays properly, although it seems to be reading from the databse a bit oddly.

What I get is:

Array
(
    [0] => Array
        (
            [day] => 2
            [month] => 1
            [year] => 2007
        )

)
Array
(
    [0] => Array
        (
            [day] => 2
            [month] => 1
            [year] => 2007
        )

    [1] => Array
        (
            [day] => 12
            [month] => 11
            [year] => 2007
        )

)

Array
(
    [0] => Array
        (
            [day] => 2
            [month] => 1
            [year] => 2007
        )

    [1] => Array
        (
            [day] => 12
            [month] => 11
            [year] => 2007
        )

    [2] => Array
        (
            [day] => 4
            [month] => 6
            [year] => 2008
        )

)

for some reason the code bit above hasn't displayed properly..

 

Which means that for each array it reads the previous rows as well and adds the next one to the end..

What I'm wanting is a list of arrays that I call call up to check some info.

So I think I'd need it to output something like:

Array
(
    [0] => Array
        (
            [day] => 2
            [month] => 1
            [year] => 2007
        )

    [1] => Array
        (
            [day] => 12
            [month] => 11
            [year] => 2007
        )

    [2] => Array
        (
            [day] => 4
            [month] => 6
            [year] => 2008
        )

)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.