RE: [PHP-DB] Re: HTML layout and arrays (WAS : Brain not working, helpneeded :-). .

From: Date: Mon, 29 Aug 2005 18:43:15 +0000
Subject: RE: [PHP-DB] Re: HTML layout and arrays (WAS : Brain not working, helpneeded :-). .
Groups: php.db 
Request: Send a blank email to php-db+get-40171@lists.php.net to get a copy of this message
Date: Mon, 29 Aug 2005 07:46:52 -0500 Message-ID: <67C5DCA3F0C94E4186175E682FBB36230B3BAC93@SJMEMXMB01.stjude.sjcrh.local> From: "Norland, Martin" <Martin.Norland@STJUDE.ORG> To: <php-db@lists.php.net> Reply-To: <php-db@lists.php.net> Subject: RE: [PHP-DB] Re: HTML layout and arrays (WAS : Brain not working,
helpneeded :-).    .
-----Original Message----- From: Neil Smith [MVP, Digital media] [mailto:php@comatose.freeserve.co.uk] The variable type you need is called an array, it has numerical indexes : In PHP you can just omit the index and it'll be automatically auto-incremented from zero, so there's no need to maintain a counter : $videos=array(); while ($row = mysql_fetch_array($sql_result)) { $videos[]["id"] = $row["id"]; $videos[]["video_link"] = $row["video_link"]; $videos[]["video_thumbnail"] = $row["video_thumbname"]; $videos[]["video_title"] = $row["video_title"]; $videos[]["video_description"] = $row["video_description"]; }; print_r($videos); [snip] You either want to be putting a $count in there, or assigning it all in one go, otherwise you're left with:
        $videos[0] == $row["id"]
        $videos[1] == $row["video_link"]
        etc.
Yeah LOL, /me slaps forehead ! It's been a long weekend, the correct solution is as Martin stated below :
while ($row = mysql_fetch_array($sql_result) {
        $videos[] = array(
                'id' => $row['id'],
                'video_link' => $row['video_link'],
                'video_thumbnail' => $row['video_thumbname'],
                'video_title' => $row['video_title'],
                'video_description' => $row['video_description'],
        );
}
Cheers - Neil

« previous php.db (#40171) next »