Jump to content

[SOLVED] Incrementally add a number to each line in a row


jaxdevil

Recommended Posts

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;
?>

$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++;
}

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.