Advertisement
gitlez

YA: Simple Image Galler From Database WOC

May 18th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.95 KB | None | 0 0
  1. <?php
  2. function html_apos($str){ /*    Helps to perserve syntax errors with apostrophies in text, by converting to html characters codes    */
  3.     return str_replace("'", "&#39;", $str);
  4. }
  5. require("includes/connect.php");
  6. $id = mysql_real_escape_string( $_GET["id"] );
  7. $sql = "SELECT * FROM project_gallery WHERE id='$id'";
  8. $result = mysql_query($sql) or die(mysql_error());
  9. $row = mysql_fetch_array($result);
  10. $name = $row['name'];
  11. $location = $row['location'];
  12. $shortdesc = $row['shortdesc'];
  13. $photo = $description = $description_title = Array();
  14. for($i=1;$i<7;++$i){
  15.     $photo[] = $row['photo' . $i];
  16.     $description[] = $row['description' . $i];
  17.     $description_title[] = $row['description_title' . $i];
  18. }
  19. ?>
  20. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-…
  21. <html xmlns="http://www.w3.org/1999/xhtml">
  22.     <head>
  23.         <script type="text/javascript">
  24.             var num=0;
  25.             var imgArray = [];
  26. <?php
  27. for( $i=0; $i<6; ++$i){
  28.     echo '            ' . 'imgArray[' . $i . "] = ['projects/" . $id . "/" . $photo[$i] . "','" . html_apos($description_title[$i]) . "','" . html_apos($description[$i]) . "'];" . PHP_EOL;
  29. }
  30. ?>
  31.             function byId(id){/*    Cross Browser getElementById()    */
  32.                 if (document.layers) {
  33.                     return document.layers[id];
  34.                 } else if (document.all) {
  35.                     return document.all[id];
  36.                 } else if (document.getElementById) {
  37.                     return document.getElementById(id);
  38.                 } else{
  39.                     return null;
  40.                 }
  41.             }
  42.             function slideshow(dir) {
  43.                 num += dir;
  44.                 if(num < 0){
  45.                     num = imgArray.length - 1;
  46.                 }else if( num == imgArray.length){
  47.                     num = 0;
  48.                 }
  49.                 byId('mypic').src = imgArray[num][0];
  50.                 byId('title').innerHTML = imgArray[num][1];
  51.                 byId('desc').innerHTML = imgArray[num][2];
  52.                 return false;
  53.             }
  54.             window.onload = function (){
  55.                 slideshow(0);
  56.             }
  57.         </script>
  58.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  59.         <title>More infomation on <?php echo $name; ?></title>
  60.         <!-- <link href="includes/gallery_style.css" rel="stylesheet" type="text/css" /> -->
  61.     </head>
  62. <body>
  63.     <div id="container" style="min-height:400px;">
  64.         <!-- First Image is now loaded by Javascript -->
  65.         <img src="#" id="mypic" name="mypic" border="0">
  66.         <br>
  67.         <!-- Place the text for the first image here -->
  68.         <p id="title">&nbsp;</p>
  69.         <p id="desc">&nbsp;</p>
  70.         <p>
  71.             <a href="#" onclick="return slideshow(-1);">« Previous</a> |
  72.             <a href="#" onclick="return slideshow(1);"> Next »</a>
  73.         </p>
  74.     </div>
  75. </body>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement