jaxdevil Posted September 3, 2008 Share Posted September 3, 2008 I am using php and mysql to dynamically generate an INF file based on files I have the names to in a database. I am trying to make each set of results increment in number. I.E. the output should be like this: &image1= &URL1= &Message1= (next row below) &image2= &URL2= &Message2= (and so forth) Right now I simply places the variable $count where the numbers should go. How can I make that variable ( $count) be a number 1 for the first row, and a number 2 for the next row, and so on? Below is the code I am using now: <?php $database = "xxx"; $dbconnect = mysql_pconnect('xxx','xxx','xxx'); mysql_select_db($database, $dbconnect); $query = "select `image_one` FROM `images` WHERE `image_one` != 'missing'"; $result = mysql_query($query, $dbconnect); while ($line = mysql_fetch_assoc($result)) { $return[] = $line; } $output = "Applet=PicStrip &ID=PicStrip &Width=400 &Height=100 &PageBgColor=F0F0FF &Accelerate=Yes &AlignTops=Yes &BgColor=F0F0FF &BorderColor=A00000 &BorderWidth=1 &ChangeDirection=No &ClickDown=Yes &DefaultTarget=_self &FocusTint=No &HotSpotWidth=400 &LoadProgressBorderColor=525461 &LoadProgressFillColor=B0B7E3 &LoadText=Loading images... &LoadTextColor=000000 &MaskWidth=25 &Name=PicStrip &ScrollAmount=15 &ScrollDelay=10 &ScrollFromMouse=Yes &ShowMasks=No &ShowVersion=No &SoundClick=5sounddown.mp3 &SoundRelease=5soundup.mp3 &Spacing=5 &StartScrollFrom=Right &Testmode=No &TintColor=FFFFFF &Transparent=No &TransparentScrollAmount=55 &TransparentScrollDelay=10"; foreach ($return as $line) { $output .= " &image".htmlentities($count)."=/prod_images/thumbs/".htmlentities($line['image_one']).".jpg &URL".htmlentities($count)."=/index.php?region=en&ctm=no&medical=Product&code=".htmlentities($line['image_one'])." &Message".htmlentities($count)."=".htmlentities($line['image_one'])." "; } echo $output; ?> Link to comment https://forums.phpfreaks.com/topic/122538-solved-incrementally-add-a-number-to-each-line-in-a-row/ Share on other sites More sharing options...
Mchl Posted September 3, 2008 Share Posted September 3, 2008 $count = 1; foreach ($return as $line) { $output .= " &image".htmlentities($count)."=/prod_images/thumbs/".htmlentities($line['image_one']).".jpg &URL".htmlentities($count)."=/index.php?region=en&ctm=no&medical=Product&code=".htmlentities($line['image_one'])." &Message".htmlentities($count)."=".htmlentities($line['image_one'])." "; $count++; } Link to comment https://forums.phpfreaks.com/topic/122538-solved-incrementally-add-a-number-to-each-line-in-a-row/#findComment-632674 Share on other sites More sharing options...
jaxdevil Posted September 3, 2008 Author Share Posted September 3, 2008 Never mind, I figured it out. I just added $count = $count+1; right above $output SK Link to comment https://forums.phpfreaks.com/topic/122538-solved-incrementally-add-a-number-to-each-line-in-a-row/#findComment-632676 Share on other sites More sharing options...
jaxdevil Posted September 3, 2008 Author Share Posted September 3, 2008 That works too Thanks man Link to comment https://forums.phpfreaks.com/topic/122538-solved-incrementally-add-a-number-to-each-line-in-a-row/#findComment-632679 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.