At 03:46 29/08/2005 +0000, you wrote:

From: "Chris Payne" <[EMAIL PROTECTED]>
To: <>
Date: Sun, 28 Aug 2005 23:45:59 -0700
MIME-Version: 1.0
Content-Type: multipart/alternative;
Subject: Brain not working, help needed :-)

Hi there everyone, have the following code:

while ($row = mysql_fetch_array($sql_result)) {
   $id = $row["id"];
   $video_link = $row["video_link"];
   $video_thumbnail = $row["video_thumbname"];
   $video_title = $row["video_title"];
   $video_description = $row["video_description"];

Now I'll be shifting through my MySQL array 6 items at a time, what I'd LIKE
to be able to do is store each item in a number string on each pass.  In
other words, the first loop would see $id being called something like $id1,
the second pass in the loop it would be $id2 and so on.

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 :

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"];



From that you can see a 6 item array, (0-5 number-indexed ), and each item is itself an array, with elements indexed by name not number - "id", "video_link" etc etc.

I THOUGHT I could do this by putting a $count ++ in the loop and then doing
something like $id$count or something like $id.$count but neither worked,

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++) {


foreach ($videos as $video_index=>$video) {
        print("Index : ".$video_index."<br />Contents : ");

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.

Cheers - Neil
PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to