Abdul Samad
Abdul Samad

Reputation: 39

how to make slider that get image from mysql last 5 images

I am new in php and I have no idea about jQuery. I have made a slider using "amzaing slider", but I want to call images from my database.
What should I do, please suggest something. How to make slider that get image from database?

    <?php
$link=mysql_connect("localhost","root","")or die("Can't Connect...");

            mysql_select_db("shop",$link) or die("Can't Connect to Database...");

            $sql="select * from book order by b_id desc limit 5 ";


$res=mysql_query($sql);
?>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <title>Amazing Slider</title>

    <!-- Insert to your webpage before the </head> -->
    <script src="sliderengine/jquery.js"></script>
    <script src="sliderengine/amazingslider.js"></script>
    <script src="sliderengine/initslider-1.js"></script>
    <!-- End of head section HTML codes -->

</head>
<body>
<div style="margin:30px auto;max-width:340px;">

    <!-- Insert to your webpage where you want to display the slider -->
    <div id="amazingslider-1" style="display:block;position:relative;margin:16px auto 32px;">
        <ul class="amazingslider-slides" style="display:none;">

      <li>  <img src="<?php echo $row[9];?>" alt="22"/></li>

        </ul>
        <ul class="amazingslider-thumbnails" style="display:none;">
            <li><img src="<?php echo $row[9];?>" /></li>

        </ul>
        <div class="amazingslider-engine" style="display:none;"><a href="http://amazingslider.com">JavaScript Slideshow</a></div>
    </div>
    <!-- End of body section HTML codes -->

</div>
</html>

Upvotes: 1

Views: 4143

Answers (3)

Abdul Samad
Abdul Samad

Reputation: 39

Thx for help . i have found my solution `

<li> <?php  while($row = mysql_fetch_row($res)){ ?>
                    <li><a href="<?php echo $row[9];?>" class="html5lightbox" data-width="500" data-height="600"> 

     <img src="<?php echo $row[9];?>" />

`

Upvotes: 1

Rizerzero
Rizerzero

Reputation: 1170

really simple ; in your database you should have an image location in a row { or image name and then prep-end a base location } and then you would

select image-name from slider-table limit 5 #to get last five rows

and then you would just list them with a foreach like you did

<li>  <img src="<?php echo $row['image-name'];?>" alt=""/></li>

Upvotes: 0

Alok Nath
Alok Nath

Reputation: 141

Better way is to store the image name into the database. And at the time of displaying the images into a slider append the image path before the image name.

Upvotes: 0

Related Questions