Advertisement
gitlez

YA: Simple Image Galler From Database WC

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