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
https://forums.phpfreaks.com/topic/91364-hours/
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
https://forums.phpfreaks.com/topic/91364-hours/#findComment-468173
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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