0

I'm new in all this. I work only from what i found on the internet.

I have a image gallery ( [http://adau.ga/peisaje.php] ) witch, true php displays informations from mysql data base. This is my .php file scrips:

<html>
<head>
    <title>Peisaje</title>
    <a href="#portfolio" onclick="galerie()"><h2>Peisaje</h2></a>
</head>
<body>
<br>
<?php
try {
    include 'http://adau.ga/conect.php';
    $interogare = $cnx->prepare("SELECT * from silvia_poze WHERE id_categorie = 1");
    $interogare->execute();
    foreach ($interogare->fetchAll() as $linie) {
        $img = $linie["poza_mare"];
        $id = $linie["id_produs"];
        $nume = $linie["titlu"];
        echo '<a href="http://adau.ga/element.php?idprod='.$id.' "class=\"buchet_mic\"><img src="images/'.$img.'" height="250" width="250" alt=""/></a>';
    }
}
catch(PDOException $e) {
    die("Conectare imposibila: " . $e->getMessage());
}
?>
</body>
</html>

This is set to open a new php file (element.php) where is displayed the information i need.

Now, i want when click on the picture to open it with fancyBox simple gallery.

I have already imported the scripts and it works if i use only html ([http://adau.ga/fancy/demo/index.php] ), but i need fancyBox to display only thous pictures that have id_category = 1 in mysql

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
Tudor
  • 980
  • 8
  • 10
  • given that your query only fetches id_categorie=1, what's the problem? the only images that would show up in your gallery would be in that category already. – Marc B Jan 29 '15 at 18:42
  • I want to open fancyBox from php and i don't know the code line. Instead of element.php i want to open the pictures with fancyBox. Thank you – Tudor Jan 29 '15 at 19:00
  • Check http://stackoverflow.com/a/17554660/1055987 and http://fancyapps.com/fancybox/#support FAQ tab, No.5 – JFK Jan 29 '15 at 20:11

1 Answers1

0

I found the solution:

<html>
<head>
    <title>Peisaje</title>

  <!-- Add jQuery library FANCY BOX GALERIE-->
  <script type="text/javascript" src="fancy/lib/jquery-1.10.1.min.js"></script>
  <!-- Add mousewheel plugin (this is optional) -->
  <script type="text/javascript" src="fancy/lib/jquery.mousewheel-3.0.6.pack.js"></script>
  <!-- Add fancyBox main JS and CSS files -->
  <script type="text/javascript" src="fancy/source/jquery.fancybox.js?v=2.1.5"></script>
  <link rel="stylesheet" type="text/css" href="fancy/source/jquery.fancybox.css?v=2.1.5" media="screen" />

  <script type="text/javascript">
   $(document).ready(function() {
    /* *  Simple image gallery. Uses default settings */
    $('.fancybox').fancybox();
   });
  </script>
  <style type="text/css">
   .fancybox-custom .fancybox-skin {
    box-shadow: 0 0 50px #222;
   }

   body {
    margin: 0 auto;
   }
  </style>

</head>
<body>
    <a href="#portfolio" id="portfolio-link" onclick="galerie()"><h2>Peisaje</h2></a>
<br>
<?php
try {
    include 'conect.php';
    $interogare = $cnx->prepare("SELECT * from silvia_poze WHERE id_categorie = 1");
    $interogare->execute();
    foreach ($interogare->fetchAll() as $linie) {
        $img = $linie["poza_mare"];
        $id = $linie["id_produs"];
        $nume = $linie["titlu"];
        echo '<a class="fancybox" href="/images/'.$img.'" data-fancybox-group="gallery" title="'.$nume.'"><img src="images/'.$img.'" height="150" width="150" alt="" /></a>';
    }
}
catch(PDOException $e) {
    die("Conectare imposibila: " . $e->getMessage());
}
?>
</body>
</html>
GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
Tudor
  • 980
  • 8
  • 10