Jump to content

$hours++


phpretard

Recommended Posts

The code below wont give the desired result.

 

while($row = mysql_fetch_array($result))

  {
  $url=$row['url'];
  $id=$row['id'];
  $num="0";
  
  $pic="messages[$num] = new Array('../$url');";  

echo $pic;

$num++;

}

 

the desired result is

 

messages[0] = new Array('../$url');

messages[1] = new Array('../$url'); 

messages[2] = new Array('../$url'); 

messages[3] = new Array('../$url'); and so on...

 

Can someone please throw a bone here?

 

-Anthony

Link to comment
Share on other sites

Hello,

You can't increment a string, which $num was before. Also, you won't get any results from putting $num inside the while loop either because it'll always reset itself to zero. To do this, you have to put it outside the loop.

$num = 0;
while($row = mysql_fetch_array($result)) {
  $url=$row['url'];
  $id=$row['id'];
  
  $pic="messages[$num] = new Array('../$url');";  
  echo $pic;
  $num++;
}

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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