Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    problem with absolute image path

    Hi all,
    i'm trying to develope a little dynamic galery based on mysql but i'm having some problems with the php script.
    So her's the code of the table:

    create table galerie (
    imageid smallint(6) not null auto_increment,
    imagename varchar(80) not null,
    imagedesc tinytext,
    date date default null,
    primary key (imageid)
    );
    for the 'imagename field' i only gave the jpeg's name, who are stocked on a folder in the '.../easyphp/www/photos/' folder.

    the script page presents like that:
    galerie.php

    PHP Code:
    <?php

    $connection 
    mysql_connect("localhost","root","197676");
    $database mysql_select_db("myodb");

    $query "SELECT count(imageid) AS ImgCount 
              FROM galerie"

    $result mysql_query($query) or die("ERROR"); 
    $ImgCount  mysql_result($result,0,"ImgCount"); 
    echo 
    "<br/><br/>$ImgCount image(s)<br/><br/>";


    // Commence la table dans laquelle sont affichées les imagettes
    echo "<table border='0' width='100%'><tr>";

    // Récupère la liste des images de la rubrique sélectionnée
    $query "SELECT imageid
              FROM galerie"

    $result mysql_query($query); 

    // On veut afficher 4 images par ligne
    $NbrImgParLigne 4;
    $NumImgLigne 0;

    // Traite les images une après les autres
    while ($row mysql_fetch_array($result))  
    {
         
    // Passe l'affichage des images à la ligne si 4 images affichées
         
    if ($NumImgLigne>=$NbrImgParLigne)
         {
             echo 
    "</tr><tr>";
             
    $NumImgLigne 0;
         } 

         
    $NumImgLigne++;

         
    // Commence une colonne de la grille pour y inclure l'image
         
    echo "<td align='center'>";
     
         
    // Récupère l'ID et le nom de l'image, en déduit le nom de la miniature
         
    $ImageID $row['imageid']; 
         
    $ImageName $row['imagename']; 
         
    $MinImageName "min_$ImageName";

         
    // Chemin absolu de l'imagette
         
    $ImagetteAbsolutePath "/photos/.$MinImageName;

         // Récupère les dimentions de l'imagette
         $JPEGRes = ImageCreateFromJPEG($ImagetteAbsolutePath);
         $xsrc = imagesx($JPEGRes);
         $ysrc = imagesy($JPEGRes);

         // Affiche le nom de l'image et sa miniature
         echo "
    $ImageName<br/><img src='$ImagetteAbsolutePath' 
               
    width='$xsrc' height='$ysrc' border='0' alt='$ImageName'>";

         // Termine la colonne de la grille pour cette image
         echo "
    </td>";


    // Termine la grille 
    echo  "
    </tr></table>";
    mysql_close();
    ?>
    browsing galerie.php i have this error:
    'Parse error: parse error, unexpected T_VARIABLE in F:\Program Files\EasyPHP 2.0b1\www\galerie_0.php on line 54'

    the error is releationed with the path that i gave on the script? i have the 'photos' folder on the www folder and that's correct '/photos/' ?
    Have also a problem with the first "select" request to have the number of pics stocked on the mysql table.....
    Appreciate your help on my little project.
    Anyways thank you a lot. Best regards Bruno
    Last edited by Cyber_type; 08-08-2007 at 07:29 PM.

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Missing a quotation mark from this line (added in red):
    Code:
    $ImagetteAbsolutePath = "/photos/".$MinImageName;

  • #3
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Also, if you were to wrap your code in [ PHP ] tags by clicking the little php icon, it would have highlighted your text for you and you may have detected this yourself .
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #4
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    @ mcjwb = it solves my first 'select' request (another stupid newbie error ). Thanks.

    I have simplified my script (get ridde of the image size funtions, later ):
    PHP Code:
    <?php

    $connection 
    mysql_connect("localhost","root","197676");
    $database mysql_select_db("myodb");

    $query "SELECT count(imageid) AS ImgCount 
              FROM galerie"

    $result mysql_query($query) or die("ERROR"); 
    $ImgCount  mysql_result($result,0,"ImgCount"); 
    echo 
    "<br/><br/>There are $ImgCount image(s) in database.<br/><br/>";

    echo 
    "<table border='0' width='100%'><tr>";
    $query "SELECT imageid
              FROM galerie"

    $result mysql_query($query); 
    $NbrImgParLigne 4;
    $NumImgLigne 0;
    while (
    $row mysql_fetch_array($result))  
    {
         if (
    $NumImgLigne>=$NbrImgParLigne)
         {
             echo 
    "</tr><tr>";
             
    $NumImgLigne 0;
         } 

         
    $NumImgLigne++;
         echo 
    "<td align='center'>";
         
    $ImageID $row['imageid']; 
         
    $ImageName $row['imagename']; 
         
    $MinImageName "min_$ImageName";
         
    $ImagetteAbsolutePath "/photos/".$MinImageName;

         echo 
    "$ImageName<br/><img src='$ImagetteAbsolutePath'  border='0' alt='$ImageName'>";

         echo 
    "</td>";

     
    echo  
    "</tr></table>";
    mysql_close();
    ?>
    but another ohmy nasty problem:
    "Notice: Undefined index: imagename in F:\Program Files\EasyPHP 2.0b1\www\galerie_.php on line 42"

    got some research for the error value, it seems that it could be an error with the name of the field on the database table, but " $ImageName = $row['imagename'];" is on the table.....
    @stupidRalph = thanks for the tip

  • #5
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Try echoing $row['imagename'] to see if that has anything and if not, look at your query, and se if there's a reason that nothing would be returned for that field

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    So, how is the following query, supposed to return anything except "imageid" -
    PHP Code:
    $query "SELECT imageid FROM galerie"
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    you're right,
    $query = "SELECT imagename
    FROM galerie";
    no more errors but only the name of the picture (.jpg).....
    one question does the variable '$ImageAbsolutePath = "/photos/";' gives the path or must i insert it into the mysql table?
    i feel that i am almost there but lots of studying php books are on my way....
    thanks everybody

  • #8
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    found it! i'm a happy newbie

    PHP Code:
    <?php

    $connection 
    mysql_connect("localhost","root","197676");
    $database mysql_select_db("myodb");

    $query "SELECT count(imageid) AS ImgCount 
              FROM galerie"

    $result mysql_query($query) or die("ERROR"); 
    $ImgCount  mysql_result($result,0,"ImgCount"); 
    echo 
    "<br/><br/>There are $ImgCount image(s) in database.<br/><br/>";

    echo 
    "<table border='0' width='100%'><tr>";

    $query "SELECT imagename, imagedesc
              FROM galerie
               ORDER BY ImageName"

    $result mysql_query($query) or die("ERROR");
    // $result = mysql_query($query);
               
    $NbrImgParLigne 4;
    $NumImgLigne 0;

    while (
    $row mysql_fetch_array($result))  
    {
         if (
    $NumImgLigne>=$NbrImgParLigne)
         {
             echo 
    "</tr><tr>";
             
    $NumImgLigne 0;
         } 

         
    $NumImgLigne++;

         echo 
    "<td align='center'>";
      
         
    $ImageName $row['imagename'];
         
    $ImageDesc $row['imagedesc'];
         
         echo 
    "<br/><img src='$ImageName'  border='0' <a href='$ImageName' target='blank'>
          <br/><img src='$ImageDesc'border='0' alt='$ImageDesc'></a>"
    ;

         echo 
    "</td>";

    echo  
    "</tr></table>";
    mysql_close();
    ?>
    so i put the /photos/image.jpg on the mysql and that's it....now it seems so easy
    also this code portion gives a way to click on the description and you have a new window with the pic but with the same size of the miniature

    echo "<br/><img src='$ImageName' border='0' <a href='$ImageName' target='blank'>
    <br/><img src='$ImageDesc'border='0' alt='$ImageDesc'></a>";
    it works for me but it seems to be poor coding, ithink so....
    so i would appreciate to have a large window on click the little one on a precise size (800*600)...PHP either javascript?
    appreciate your advises or some tutorials or article that could solve my problem...
    best regards bruno
    Last edited by Cyber_type; 08-09-2007 at 02:54 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •