简体   繁体   中英

if i have a value in database field as 10 then i want to show 10 images in php

if i have a value in database field as 10 then i want to show 10 images or numbers like this (1 2 3 4 5 6 7 8 9 10 ). if i have a value in database field as 12 then i want to show 10 images or numbers like this (1 2 3 4 5 6 7 8 9 10 11 12 ).

i am new to php so i didn't get any idea please help me.. i have written code like this.....

 $sql = "select * from hajj_umrah_package";

        $res = mysql_query($sql, $conn); 

        if( mysql_num_rows($res) > 0) {
            while($row = mysql_fetch_array($res))
        {

            $m = $row['available'];


        echo '<div class="col-md-12">
          <div class="panel panel-primary"> 
           <div class="panel-heading"> 
            <h3 class="panel-title">'.$row["package_title"].'</h3> 
           </div> 
          <div class="panel-body um-body"> <span style="color:#333;">'.$row["package_dsp"].'</span> <br> <br>
                 <span>'.$m++.'</span>



           </div> 

         </div>
        </div>';
        }
        }

If you query to get $m works correct, you can use a for loop:

for ($i=1; $i<=$m; $i++) {
    echo $i;
    echo "<img src='imgpath.png'>"
}

You can learn more about for loops in the php manual: http://php.net/manual/de/control-structures.for.php

If you want to parameterize the path of your image, use this:

echo "<img src='imgpath". $i . ".png'>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM