开发者

How can I get images from the database to be output into a gallery slider?

I have made a diary where I have a menu that echoes out every day and a text box that echoes the day's entry, the page also contains an image slider that has a slideshow of some images.

So basically this is the code that calls the details from the database -

$sqlCommand = "SELECT * FROM images WHERE pageorder='$pageid'"; 
$result = mysql_query($sqlCommand) or die (mysql_error());

$allimages = '';
while ($row = mysql_fetch_array($result)) { 
    $images = $row['images'];
    $ititle = $row['title'];
    $idesc = $row['description'];

$allimages = '<li class="sliderImage"><img src=' . $images . ' /><span class="bottom"><strong>' . $ititle . '</strong><br />' . $idesc . '</span></li>';}

this is how I echo it

<div class='sliderholder'><div id='sliderholder'><div id='slider'><ul id='sliderContent'>
<?php echo $allimages ?>
<div class='clear sliderImage'></div></ul></div></div>

I have two databases, one is called pages that echoes out all the text and menu etc, then the other database contains links to the images with a column for pageorder so 1st January will have a page order of 1 and 31 december will be 365. This corresponds with the page id.

The way I have put the details into the images mysql table:

 id | images       | title         | description         | page order
---------------------------------------------------------------
 1  | images/1.jpg | title image 1 | Image description 1 | 1
 2  | images/2.jpg | title image 2 | Image description 2 | 1
 3  | images/3.jpg | title image 3 | Image description 3 | 2
 4  | images/4.jpg | title image 4 | Image description 4 | 2

so when I load the first page I want the image slider to sh开发者_JAVA技巧ow images 1 and 2. But what the slider does is that it shows only image 1, it will fade away and instead of showing the second image it goes back to image 1.

What should I do so that if I say for example select page 300 that will have a pageid of 300, and page order of 300 and all the images that are associated with the number 300, be it 2 images or 50 it should echo them in such a way that it slides through them all!?


You're setting $allimages on each iteration. Use .= rather than =.

$allimages .= '<li class="sliderImage"><img src=' // ...
//         ^^
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜