imimin Posted July 27, 2009 Share Posted July 27, 2009 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! Link to comment https://forums.phpfreaks.com/topic/167647-how-to-auto-increment-numeral-between-brackets/ Share on other sites More sharing options...
gevans Posted July 27, 2009 Share Posted July 27, 2009 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++ } ?> Link to comment https://forums.phpfreaks.com/topic/167647-how-to-auto-increment-numeral-between-brackets/#findComment-884136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.