Jump to content

How to auto increment numeral between brackets?


imimin

Recommended Posts

How could I auto-increment the numeral between the brackets on line 10 of the below code (fadeimages[0]) so the nuneral increases by 1 for each iteration (starting with numeral 0)?  Example, if I have 3 iterations the output would look like:

 

fadeimages[0]=["photo1.jpg", "", ""]
fadeimages[1]=["photo2.jpg", "", ""]
fadeimages[2]=["photo3.jpg", "", ""]

 

<?php
/*$cat = mysql_real_escape_string($_GET['cat']);*/
$cat='all';
$get_items = "SELECT * FROM poj_products WHERE cat='$cat'";
$get_items = mysql_query($get_items);
   while($item_row = mysql_fetch_assoc($get_items))
   {
   extract($item_row);
   echo 'fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/'.$item_row['img-no_path'].'", "", ""]';
   '\n';
   }
?>

 

Thank you!

If you're doing what I think you're trying to do there are some further problems in the code, but I'll let you sort them out;

 

<?php
/*$cat = mysql_real_escape_string($_GET['cat']);*/
$cat='all';
$get_items = "SELECT * FROM poj_products WHERE cat='$cat'";
$get_items = mysql_query($get_items);
$i = 0;
while($item_row = mysql_fetch_assoc($get_items))
{
extract($item_row);
echo 'fadeimages['.$i.']=["http://www.patternsofjoy.com/images/thumbs/'.$item_row['img-no_path'].'", "", ""]';
echo '\n';
$i++
}
?>

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.