ajax 图片展示,手动展示幻灯片
翻页的地方在图片上方,当然也可以用css+div把翻页的和文字移动到图片里面合适的位置
数据库很简单,就是3个字段,id,picturetitle,picturename
index.php
XML/HTML Code复制内容到剪贴板
- <html>
- <head>
- <!-- load jquery -->
- <script type="text/javascript" src="js/jquery.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- $(".getPicButton").live("click", function() {
- var myPictureId = $(this).attr('id');
- var getImgId = myPictureId.split("-");
- getPicture(getImgId[1]);
- return false;
- });
- });
- function getPicture(myPicId)
- {
- $('#picture').html('<div style="margin-top:50px;width:500px;" align="center" ><img src="loader.gif" /></div>');
- var myData = 'picID='+myPicId;
- jQuery.ajax({
- url: "getpicture.php",
- type: "GET",
- dataType:'html',
- data:myData,
- success:function(response)
- {
- $('#picture').html(response);
- }
- });
- }
- </script>
- <div id="picture">
- <?php require('getpicture.php'); ?>
- </div>
getpicture.php
PHP Code复制内容到剪贴板
- <?php
- include("conn.php");
- if(isset($_GET["picID"]) && is_numeric($_GET["picID"]))
- {
- $curPicId = $_GET["picID"];
- }else{
- $curPicId =1;
- }
- //Connect to Database
- //Get the Picture
- $Result = mysql_query("SELECT picturetitle,picturename FROM content WHERE id=$curPicId");
- if($Result)
- {
- //empty variables, just incase
- $picTitle=''; $picName=''; $PrvLink='';$NextLink='';
- $row = mysql_fetch_row($Result);
- $picTitle = $row[0];
- $picName = $row[1];
- //Get previous Picture
- $PrvResult = mysql_query("SELECT * FROM content WHERE id<$curPicId ORDER BY id DESC");
- $PrvPic = mysql_fetch_row($PrvResult);
- if($PrvPic)
- {
- $PrvLink = '<a href="#" id="getPic-'.$PrvPic[0].'" title="'.$PrvPic[1].'" class="getPicButton"><img src="prev.png" border="0" /></a>';
- }
- //Get next Picture
- $NxtResult = mysql_query("SELECT * FROM content WHERE id>$curPicId ORDER BY id ASC");
- $NxtPic = mysql_fetch_row($NxtResult);
- if($NxtPic)
- {
- $NextLink = '<a href="#" id="getPic-'.$NxtPic[0].'" title="'.$NxtPic[1].'" class="getPicButton"><img src="next.png" border="0" /></a>';
- }
- //$picdata = array('pic'=>$picName,'pictitle'=>$picTitle,'prvid'=>$PrvPicID,'prvtitle'=>$PrvPicTitle,'nxtid'=>$NxtPicID,'nxttitle'=>$NxtPicTitle);
- echo '<table width="500" border="0" cellpadding="5" cellspacing="0">
- <tr>
- <td><table width="100%" border="0" cellpadding="5" cellspacing="0">
- <tr>
- <td width="10%">'.$PrvLink.'</td>
- <td width="80%" align="center"><h3>'.$picTitle.'</h3></td>
- <td width="10%">'.$NextLink.'</td>
- </tr>
- </table></td>
- </tr>
- <tr>
- <td align="center"><img src="../'.$picName.'" /></td>
- </tr>
- </table>';
- //json data
- //echo json_encode($picdata);
- }
- ?>
原文地址:http://www.freejs.net/article_jquerytupiantexiao_12.html