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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>-----Original Message-----
>From: Neil Smith [MVP, Digital media]
[mailto:php@xxxxxxxxxxxxxxxxxxxxxxxx] 
>
>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<count($videos); $i++) {
>         print_r($videos[$i]);
>}
>
>or
>
>foreach ($videos as $video_index=>$video) {
>         print("Index : ".$video_index."<br />Contents : ");
>         print_r($video);
>}
>
>
>>I have 6 items on the page so I can hardcode <?=$id1?> for item 1 and
>
>Instead, use <?=$videos[0]["video_description"]?> and so on.

And use <?php instead of <? just to be safe :)

cheers,
- Martin Norland, Sys Admin / Database / Web Developer, International
Outreach x3257

The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux