RE: [PHP-DB] Re: HTML layout and arrays (WAS : Brain not working, helpneeded :-). .
Date: Mon, 29 Aug 2005 07:46:52 -0500 Message-ID: <[EMAIL PROTECTED]> From: "Norland, Martin" <[EMAIL PROTECTED]> To: Reply-To: Subject: RE: [PHP-DB] Re: HTML layout and arrays (WAS : Brain not working, helpneeded :-).. >-Original Message- >From: Neil Smith [MVP, Digital media] [mailto:[EMAIL PROTECTED] > >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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: HTML layout and arrays (WAS : Brain not working, helpneeded :-). .
Norland, Martin wrote: 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'], ); } or you could use the row id (assuming that $row['id'] is a unique field for each row) as your 'count' like this: while ($row = mysql_fetch_array($sql_result) { $videos[$row['id']]['id'] = $row['id']; $videos[$row['id']]['video_link'] = $row['video_link']; etc... } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: HTML layout and arrays (WAS : Brain not working, helpneeded :-). .
>-Original Message- >From: Neil Smith [MVP, Digital media] [mailto:[EMAIL PROTECTED] > >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. 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'], ); } >You can in PHP using "variable variables" but it gets very complicated and >hard to debug. >Stick with arrays so you can use stuff like > >for ($i=0; $i print_r($videos[$i]); >} > >or > >foreach ($videos as $video_index=>$video) { > print("Index : ".$video_index."Contents : "); > print_r($video); >} > > >>I have 6 items on the page so I can hardcode for item 1 and > >Instead, use and so on. And use http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php