SitePoint Sponsor

User Tag List

Page 27 of 31 FirstFirst ... 17232425262728293031 LastLast
Results 651 to 675 of 767
  1. #651
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi everyone I am a bit of a newbie when it comes to PHP so bear with me.

    I am trying to create a image gallery on my home page that only displays the last 4 images that i uploaded.

    Currently I am uploading the files to the server using the gallery script in the tutorial, and then copying the image id and cat links. But this is time consuming and would be nice to automate.

    The code I use on the main page is below:

    <img src="../portfolio/tb_01.jpg" alt="Gaming" onmouseover="showtrail('../portfolio/01.jpg','Pending Launch!<br />Gaming','Pending Launch!<br />Gaming','1',400,1)" onmouseout="hidetrail();" height="120" width="160"></div>

    This code allows the user to mouse over to see the larger version.

    Any Help with this would be much appreciated.

    Cheers and Thanks in advance

    Ryan

  2. #652
    Kooswillem
    SitePoint Community Guest
    @Ryan:

    Please descibe waht you do exactly in detailed steps, what happens and what you would like to happen.

  3. #653
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had gone though this entire thread. I must thank Mayank Gandhi who wrote this tutorial and all those who have contributed in helping out in this thread. I have made a gallery page in my site where I have got a few categories. At the moment, I only have about 7 to 8 pictures in each category. I have been able to build a page with links to the different categories, which when clicked lead me to the page with the thumbnails of my images in a particular category. On clicking the thumbnails, I am lead to the page containing the full image.

    I have also managed to have an admin section whereby I am able to upload and delete images.

    I now need to add the following functions:

    1. Add some code to my viewgallery page so that I can have a Next and Previous link between the different pictures in one category.

    2. Have a pagination script where I can go to different pages containing the thumbnails in one particular category.

    3. Have the ability to add, delete and edit categories.

    I think no.2 and no.3 have been discussed in this thread and I am going to try that out myself before I come to the forum for any help that I may require.

    As of now, I am trying out no. 1 and have been struggling for a long time.

    I first tried writing this:
    PHP Code:
     
    $pid 
    $_GET['pid']; 
    $next $pid+1;
    $prev $pid-1
    echo 
    "<a href='viewgallery.php?cid=$cid&pid=$next'>Next</a>&gt; "
    But that did not work because when I deleted some pictures in between, I had gaps and when I was on pid 5 and clicked on the next link, I got the result Photo not found because my photo with pid=5 had already been deleted.

    I have posted questions to the php thread and have tried out the various methods suggested by my sitepoint forum friends, but I have not succeeded so far.

    The full code of my current viewgallery page is as follows:

    PHP Code:
    <?php
     
    include("config.inc.php");
     
     
    // initialization
     
    $result_array = array();
     
    $counter 0;
     
    $cid = (int)($_GET['cid']);
     
    $pid = (int)($_GET['pid']);
     
    // Category Listing
     
    if( empty($cid) && empty($pid) )
     {
      
    $number_of_categories_in_row 4;
      
    $result mysql_query"SELECT c.category_id,c.category_name,COUNT(photo_id)
          FROM gallery_category as c
          LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
          GROUP BY c.category_id" 
    );
      while( 
    $row mysql_fetch_array$result ) )
      {
       
    $result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
     
     
      }
      
    mysql_free_result$result ); 
      
    $result_final "<tr>\n";
      foreach(
    $result_array as $category_link)
      {
       if(
    $counter == $number_of_categories_in_row)
       { 
        
    $counter 1;
        
    $result_final .= "\n</tr>\n<tr>\n";
       }
       else
       
    $counter++;
       
    $result_final .= "\t<td>".$category_link."</td>\n";
      }
      if(
    $counter)
      {
       if(
    $number_of_categories_in_row-$counter)
       
    $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'>&nbsp;</td>\n";
       
    $result_final .= "</tr>";
      }
     }
     
     
    // Thumbnail Listing
     
    else if( $cid && empty( $pid ) )
     {
      
    $number_of_thumbs_in_row 5;
      
    $result mysql_query"SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE 
    photo_category='"
    .addslashes($cid)."'" );
      
    $nr mysql_num_rows$result );
      if( empty( 
    $nr ) )
      {
       
    $result_final "\t<tr><td>No Category found</td></tr>\n";
      }
      else
      {
       while( 
    $row mysql_fetch_array$result ) )
       {
        
    $result_array[] = "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'><img 
    src='"
    .$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /></a>";
       }
       
    mysql_free_result$result ); 
       
    $result_final "<tr>\n";
    "<a href='viewgallery.php?cid=$cid'>$category_name</a></td>\n</tr>\n";
     
       foreach(
    $result_array as $thumbnail_link)
       {
        if(
    $counter == $number_of_thumbs_in_row)
        { 
         
    $counter 1;
         
    $result_final .= "\n</tr>\n<tr>\n";
        }
        else
        
    $counter++;
        
    $result_final .= "\t<td>".$thumbnail_link."</td>\n";
     
       }
     
       if(
    $counter)
       {
        if(
    $number_of_photos_in_row-$counter)
       
    $result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'>&nbsp;</td>\n";
        
    $result_final .= "</tr>";
     
     
     
     
     
     
       }
      }
     }
     
     
     
    // Full Size View of Photo
     
    else if( $pid )
     {
      
    $result mysql_query"SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".$pid."'" );
      list(
    $photo_caption$photo_filename) = mysql_fetch_array$result );
      
    $nr mysql_num_rows$result );
      
    mysql_free_result$result ); 
      if( empty( 
    $nr ) )
      {
       
    $result_final "\t<tr><td>No Photo found</td></tr>\n";
      }
      else
      {
       
    $result mysql_query"SELECT category_name FROM gallery_category WHERE category_id='".addslashes
    ($cid)."'" );
       list(
    $category_name) = mysql_fetch_array$result );
       
    mysql_free_result$result );
     
       
    $result_final .= "<tr>\n\t<td>
     
     
        <a href='viewgallery.php'>Categories</a> &gt; 
          <a href='viewgallery.php?cid=
    $cid'>$category_name</a>                      
    </td>\n</tr>\n"
    ;
     
    //Next and Previous Links
    $sql mysql_query("SELECT photo_id
    , photo_filename
    , photo_caption
    , photo_category
    , (SELECT MIN(photo_id)
    FROM gallery|_photos
    WHERE photo_category = this.photo_category
    AND photo_id > this.photo_id )
    AS next_photo_id
    , ( SELECT MAX(photo_id)
    FROM gallery_photos
    WHERE photo_category = this.photo_category
    and photo_id < this.photo_id )
    AS prev_photo_id
    FROM gallery_photos AS this
    WHERE photo_id = 
    {$id}");
     
    $result mysql_query($sql);
    $row mysql_fetch_array($result);
    $link '<a href="viewgallery.php?cid=$cid&pid=%s">%s</a>'
    //previous link:
    printf($link$row['prev_photo_id'], 'Previous') &gt;
    //next link:
    printf($link$row['next_photo_id'], 'Next');
     
     
     
       
    $result_final .= "<tr>\n\t<td align='center'>
         <br />
         <img src='"
    .$images_dir."/".$photo_filename."' border='0' width= '550'  
    alt='"
    .$photo_caption."' />
         <br />
         
    $photo_caption
         </td>
         </tr>"
    ;
      }
     }
    // Final Output
    echo <<<__HTML_END
    When I try the sql code for the next and previous links outside of php, I am getting what I want. But I am certainly going wrong in using my php code.

    With the current code, I am getting the following:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\pvCom\viewgallery.php on line 189
    PreviousNext
    (When I click on these links, I go back to my the page containing the names of the categories and I see this on my address bar:http://127.0.0.1/pvCom/viewgallery.php?cid=$cid&pid=

    While writing the php script for retrieving the MySQL code for the next previous links, I tried writing the error code like this. When I write $result = mysql_query($sql) or die(mysql_error()); I get the result, Query was empty on clicking on the thumbnail. But the moment, I remove the error code and write only $result = mysql_query($sql); I am again able to get the full picture on clicking the thumbnail but get the error, Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\pvCom\viewgallery.php on line 189 (that is the line after error code).


    I would be really grateful if someone can help me out.

  4. #654
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    The code you've posted for viewgallery.php is not all there. the code only goes up to line 160, is there more?

    Also, please check within this code too:
    PHP Code:
    $sql mysql_query("SELECT photo_id
    , photo_filename
    , photo_caption
    , photo_category
    , (SELECT MIN(photo_id)
    FROM gallery|_photos
    WHERE photo_category = this.photo_category
    AND photo_id > this.photo_id )
    AS next_photo_id
    , ( SELECT MAX(photo_id)
    FROM gallery_photos
    WHERE photo_category = this.photo_category
    and photo_id < this.photo_id )
    AS prev_photo_id
    FROM gallery_photos AS this
    WHERE photo_id = 
    {$id}"); 
    You have this:
    PHP Code:
    , (SELECT MIN(photo_id)
    FROM gallery|_photos 
    It should be this:
    PHP Code:
    , (SELECT MIN(photo_id)
    FROM gallery_photos 
    Try the above code change first as the error message suggests the mysql query is not correct and no data is being collected.

  5. #655
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am sorry, I left out the last few lines after
    PHP Code:
    // Final Output
    echo <<<__HTML_END 
    which I have given below:

    PHP Code:
    <html>
    <
    head>
     <
    title>Gallery View</title>
    </
    head>
    <
    body>
    <
    table width='100%' border='0' align='center' style='width: 100%;'>
    $result_final  
    </table>
    </
    body>
    </
    html>
    __HTML_END;
    ?> 
    I also rectified the typing error which I had made
    , (SELECT MIN(photo_id)
    FROM gallery_photos
    but I really don't know how, I continue to get the same error message.

  6. #656
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I feel that my sql query is correct. Now, I have deleted my photos containing the ids, 6, 7, 8 and 9. Hence, when I give the photo_id as 5, I am getting the correct result ie the next_photo_id as 10 and the prev_photo_id as 4. Doesn't that indicate that my query is correct? I am giving below the sql query that I used outside of php and the result that I got.

    Code SQL:
    mysql> SELECT photo_id
        -> , photo_filename
        -> , photo_caption
        -> , photo_category
        -> , (SELECT MIN(photo_id)
        -> FROM gallery_photos
        -> WHERE photo_category = this.photo_category
        -> AND photo_id > this.photo_id )
        -> AS next_photo_id
        -> , ( SELECT MAX(photo_id)
        -> FROM gallery_photos
        -> WHERE photo_category = this.photo_category
        -> AND photo_id < this.photo_id )
        -> AS prev_photo_id
        -> FROM gallery_photos AS this
        -> WHERE photo_id = 5;
    +----------+----------------+------------------+----------------+---------------
    +---------------+
    | photo_id | photo_filename | photo_caption    | photo_category | next_photo_id
    | prev_photo_id |
    +----------+----------------+------------------+----------------+---------------
    +---------------+
    |        5 | 5.jpg          | Australia tour 2 |              1 |            10
    |             4 |
    +----------+----------------+------------------+----------------+---------------
    +---------------+
    1 ROW IN SET (0.39 sec)
    mysql>

  7. #657
    Joff
    SitePoint Community Guest
    is there anyway to include lightbox to the display i tried adding the rel='lightbox' to the img href on the viewgal.php but it never loads the image

  8. #658
    Anonymous
    SitePoint Community Guest
    how to delete image in folder image,because i'm try to delete category,image still in folder image,

    can help me thank you

  9. #659
    okebro
    SitePoint Community Guest
    This script it's not work,can you help




    Deleting a Photo

    function delete_photo($photo_id)
    {
    $result = mysql_query("
    SELECT photo_filename
    FROM gallery_photo
    WHERE photo_id = '" . addslashes($photo_id) . "'
    ");
    list($filename) = mysql_fetch_array($result);
    mysql_free_result($result);

    unlink($images_dir . '/' . $filename);

    mysql_query("
    DELETE FROM gallery_photo
    WHERE photo_id='" . addslashes($photo_id) . "'
    ");
    }

    Call: delete_photo(PHOTO_ID);

  10. #660
    ken
    SitePoint Community Guest
    Hello this code cannot work ,can anybody help me, thank You

    <?php

    include("config.inc.php");


    ?>






    <?php

    function delete_photo($photo_id)
    {
    $result = mysql_query("
    SELECT photo_filename
    FROM gallery_photo
    WHERE photo_id = '" . addslashes($photo_id) . "'
    ");
    list($filename) = mysql_fetch_array($result);
    mysql_free_result($result);

    unlink($images_dir . '/' . $filename);

    mysql_query("
    DELETE FROM gallery_photo
    WHERE photo_id='" . addslashes($photo_id) . "'
    ");
    }
    ?>





    <form name="delete_photo" action="caba1.php" method="post">



    <b>Delete Category:</b><br />

    <?php echo($photos_list); ?>

    <input type="submit" value="delete_photo" name="action" />



    </form>

  11. #661
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by jppp View Post
    I feel that my sql query is correct. Now, I have deleted my photos containing the ids, 6, 7, 8 and 9. Hence, when I give the photo_id as 5, I am getting the correct result ie the next_photo_id as 10 and the prev_photo_id as 4. Doesn't that indicate that my query is correct? I am giving below the sql query that I used outside of php and the result that I got.

    Code SQL:
    mysql> SELECT photo_id
        -> , photo_filename
        -> , photo_caption
        -> , photo_category
        -> , (SELECT MIN(photo_id)
        -> FROM gallery_photos
        -> WHERE photo_category = this.photo_category
        -> AND photo_id > this.photo_id )
        -> AS next_photo_id
        -> , ( SELECT MAX(photo_id)
        -> FROM gallery_photos
        -> WHERE photo_category = this.photo_category
        -> AND photo_id < this.photo_id )
        -> AS prev_photo_id
        -> FROM gallery_photos AS this
        -> WHERE photo_id = 5;
    +----------+----------------+------------------+----------------+---------------
    +---------------+
    | photo_id | photo_filename | photo_caption    | photo_category | next_photo_id
    | prev_photo_id |
    +----------+----------------+------------------+----------------+---------------
    +---------------+
    |        5 | 5.jpg          | Australia tour 2 |              1 |            10
    |             4 |
    +----------+----------------+------------------+----------------+---------------
    +---------------+
    1 ROW IN SET (0.39 sec)
    mysql>
    I think your going to struggle the way your trying to do it jppp.

    Let me think about this as I may have a better solution for your problem.

  12. #662
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    OK, try this solution.

    PHP Code:
    <pre>
    <?php
    include('config.inc.php');

    $everything = array();

    $all mysql_query("SELECT min(photo_id) AS First
                            , min(photo_caption) AS Cap
                            , min(photo_filename) AS File
                            , min(photo_category) AS Cate
                            , ( SELECT max(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id < '"
    .$id."' ) as Prev 
                            , ( SELECT min(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id > '"
    .$id."' ) as Next
                          FROM gallery_photos
                          WHERE photo_id = '"
    .$id."'"); 
                          
    while(
    $list mysql_fetch_array$all ))    {
        
    $everything[] = array('now' => $list['First'], 'file' => $list['File'], 'caption' => $list['Cap'],'category' => $list['Cate'], 'next' => $list['Prev'], 'prev' => $list['Next']);
    }
    mysql_free_result$all );

                echo 
    '        <table width="490" border="0" cellpadding="0" cellspacing="0">';
                echo 
    '            <tr>';

    foreach(
    $everything as $s => $sval)    {
                echo 
    '            <td><div align="left">This ID: '.$sval['now'].'</div>';
                echo 
    '            <div align="left">The Filename: '.$sval['file'].'</div>';
                echo 
    '            <div align="left">Its Caption: '.$sval['caption'].'</div>';
                echo 
    '            <div align="left">Which Category: '.$sval['category'].'</div>';
                echo 
    '            <div align="left">Next: '.$sval['next'].'</div>';
                echo 
    '            <div align="left">Previous: '.$sval['prev'].'</div></td>';
    }
                echo 
    '    </tr>';
                echo 
    '</table>';
                echo 
    "\n";
    print_r($everything);
    ?>
    </pre>
    The above code will display (I've used the ID '6520' from my website):
    This ID: 6520

    The Filename: 6520_4863.jpg

    Its Caption: Hydrema 910

    Which Category: 4863

    Next: 6519

    Previous: 6521

    Array

    ( [0] => Array

    (

    [now] => 6520

    [file] => 6520_4863.jpg

    [caption] => Hydrema 910

    [category] => 4863

    [next] => 6519

    [prev] => 6521

    )
    )
    I hope this has helped.

    spence

  13. #663
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for the code, spence_noodle.
    The code is displaying exactly what you said. I then tried to get the links to the next and previous image but I am not able to do it.

    I tried something like this:

    PHP Code:
    $link '<a href="viewgallery.php?cid=$cid&pid=$pid>%s</a>
    printf($link, $sval['
    next'], 'Next'); 
    But I am getting a parse error. I think I am too much of a newbie to be able to even utilise your code. Can I be given some further help?

    This is the part of my code where I added my snippet above.
    PHP Code:
    mysql_free_result$all );
                echo 
    '        <table width="490" border="0" cellpadding="0" cellspacing="0">';
                echo 
    '            <tr>';
    foreach(
    $everything as $s => $sval)    {
                echo 
    '            <td><div align="left">This ID: '.$sval['now'].'</div>';
                echo 
    '            <div align="left">The Filename: '.$sval['file'].'</div>';
                echo 
    '            <div align="left">Its Caption: '.$sval['caption'].'</div>';
                echo 
    '            <div align="left">Which Category: '.$sval['category'].'</div>';
     
    $link '<a href="viewgallery.php?cid=$cid&pid=$pid>%s</a>
    printf($link, $sval['
    next'], 'Next');
                echo '            
    <div align="left">Next'.$sval['next'].'</div>';
     
                echo '            
    <div align="left">Previous'.$sval['prev'].'</div></td>';
    }
                echo '    
    </tr>';
                echo '
    </table>';
                echo "\n"; 
    I also tried modifying my earlier code which I had been trying before I wrote to you.
    I am now not getting the Resource Id error but what I am facing when I use that code is as follows:
    I get 2 Next links side by side on the first full image page. When I click on the Next Link and go to the next page, I see the previous and next links which work. Then, when I go to the last image of a particular category, I still get the Next link and am taken to the page containing the thumbnails of different categories. In my second caegory which contains only one image, the next and previous links still appear and both of them again take me back to the category page. t I hope I am clear in expressing myself.
    This is the code which I had been trying. I am not able to remove one of the Next links on the first page without getting an error.
    PHP Code:
    //Next and Previous Links
    //initialize the start to 0
    if(!$totrow$totrow=0;
     
    $my_query mysql_query("SELECT photo_id
    , photo_filename
    , photo_caption
    , photo_category
    , (SELECT MIN(photo_id)
    FROM gallery_photos 
    WHERE photo_category = this.photo_category
    AND photo_id > this.photo_id )
    AS next_photo_id
    , ( SELECT MAX(photo_id)
    FROM gallery_photos 
    WHERE photo_category = this.photo_category
    and photo_id < this.photo_id )
    AS prev_photo_id
    FROM gallery_photos AS this
    WHERE photo_id = '
    $pid'") or die(mysql_error()); 
     
     
    $totrow=mysql_num_rows($my_query);
    $row=mysql_fetch_array($my_query);
     
    $link '<a href="viewgallery.php?cid=$cid&pid=%s">%s</a>'
    if (
    $totrow $row)
     
    //previous link:
     
    $link '<a href="viewgallery.php?cid=$cid&pid=$pid">%s</a>';
     
    if(
    $pid-1=="0")
    {
    //next link:
    if($next_photo_id=="")
    printf($link$row['next_photo_id'], 'Next');}
    else
    printf($link$row['prev_photo_id'], 'Previous') &gt;
    printf($link$row['next_photo_id'], 'Next');
     
     
       
    $result_final .= "<tr>\n\t<td align='center'>
         <br />
         <img src='"
    .$images_dir."/".$photo_filename."' border='0' width= '550'  
    alt='"
    .$photo_caption."' />
         <br />
         
    $photo_caption
         </td>
         </tr>"
    ;
      }
     }
     
    // Final Output
    echo <<<__HTML_END
    <html>
    <head>
     <title>Gallery View</title>
    </head>
    <body>
    <table width='100%' border='0' align='center' style='width: 100%;'>
    $result_final  
    </table>
    </body>
    </html>
    __HTML_END; 
    Is this whole approach going to be very difficult?
    spence_noodle, should I try the code that you gave and try getting the Next and Previous links to appear on my page? I have been trying to modify both the codes for so many days without success.

  14. #664
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I'm so sorry jppp. My mistake with my coding.

    Don't worry though I've sorted it out and even tested it.

    I did try your code and I must say it's a bit messy, never mind you will learn, I'm still learning even at this stage.

    Anyway, the coding error was to do with the 'while' listing, I got the Next and Previous the wrong way round.

    The code below has the next and previous links working.
    PHP Code:
    <pre>
    <?php
    include('config.inc.php');
    $id '6520';

    $everything = array();

    $all mysql_query("SELECT min(photo_id) AS First
                            , min(photo_caption) AS Cap
                            , min(photo_filename) AS File
                            , min(photo_category) AS Cate
                            , ( SELECT max(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id < '"
    .$id."' ) as Prev
                            , ( SELECT min(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id > '"
    .$id."' ) as Next
                          FROM gallery_photos
                          WHERE photo_id = '"
    .$id."'
                          ORDER BY photo_id ASC"
    ); 
                          
    while(
    $list mysql_fetch_array$all ))    {
        
    $everything[] = array('now' => $list['First'], 'file' => $list['File'], 'caption' => $list['Cap'],'category' => $list['Cate'], 'next' => $list['Next'], 'prev' => $list['Prev']);
    }
    mysql_free_result$all );
                echo 
    '        <table width="490" border="0" cellpadding="0" cellspacing="0">';
                echo 
    '            <tr>';
    foreach(
    $everything as $s => $sval)    {
                echo 
    '            <td><div align="left">This ID: '.$sval['now'].'</div>';
                echo 
    '            <div align="left">The Filename: '.$sval['file'].'</div>';
                echo 
    '            <div align="left">Its Caption: '.$sval['caption'].'</div>';
                echo 
    '            <div align="left">Which Category: '.$sval['category'].'</div>';
                echo 
    '            <div align="left">Next: <a href="catmain.php?cid='.$sval['category'].'&pid='.$sval['next'].'">'.$sval['next'].'</a></div>';
     
                echo 
    '            <div align="left">Previous: <a href="catmain.php?cid='.$sval['category'].'&pid='.$sval['prev'].'">'.$sval['prev'].'</a></div></td>';
    }
                echo 
    '    </tr>';
                echo 
    '</table>';
                echo 
    "\n"

    print_r($everything);
    ?>
    </pre>
    Near the beginning I've used the id 6520, one of my own for testing, this should be deleted and then add your own code. Also, if there's no other photo before or after the one displayed the link will not be shown.

    So you will need to do something like this to make sure the Next or Prev is not displayed:

    PHP Code:
    // if next is set display link
    if(isset($sval['next'])) {
        
    $next '<div align="left">Next: <a href="catmain.php?cid='.$sval['category'].'&pid='.$sval['next'].'">'.$sval['next'].'</a></div>';
    }

    echo 
    $next
    Here's the full code:
    PHP Code:
    <pre>
    <?php
    include('config.inc.php');
    $id '6520';

    $everything = array();

    $all mysql_query("SELECT min(photo_id) AS First
                            , min(photo_caption) AS Cap
                            , min(photo_filename) AS File
                            , min(photo_category) AS Cate
                            , ( SELECT max(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id < '"
    .$id."' ) as Prev 
                            , ( SELECT min(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id > '"
    .$id."' ) as Next
                          FROM gallery_photos
                          WHERE photo_id = '"
    .$id."'
                          ORDER BY photo_id ASC"
    ); 
                          
    while(
    $list mysql_fetch_array$all ))    {
        
    $everything[] = array('now' => $list['First'], 'file' => $list['File'], 'caption' => $list['Cap'],'category' => $list['Cate'], 'next' => $list['Next'], 'prev' => $list['Prev']);
    }
    mysql_free_result$all );
                echo 
    '        <table width="490" border="0" cellpadding="0" cellspacing="0">';
                echo 
    '            <tr>';
    foreach(
    $everything as $s => $sval)    {
        
    // if next is set display link
        
    if(isset($sval['next'])) {
            
    $next '<div align="left">Next: <a href="catmain.php?cid='.$sval['category'].'&pid='.$sval['next'].'">'.$sval['next'].'</a></div>';
        }
        
        
    // if prev is set display link
        
    if(isset($sval['prev'])) {
            
    $prev '<div align="left">Prev: <a href="catmain.php?cid='.$sval['category'].'&pid='.$sval['prev'].'">'.$sval['prev'].'</a></div>';
        }
        
                echo 
    '            <td><div align="left">This ID: '.$sval['now'].'</div>';
                echo 
    '            <div align="left">The Filename: '.$sval['file'].'</div>';
                echo 
    '            <div align="left">Its Caption: '.$sval['caption'].'</div>';
                echo 
    '            <div align="left">Which Category: '.$sval['category'].'</div>';
                echo 
    $next;
                echo 
    $prev;
    }
                echo 
    '    </tr>';
                echo 
    '</table>';
                echo 
    "\n"

    print_r($everything);
    ?>
    </pre>
    spence

  15. #665
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did try your code and I must say it's a bit messy,
    - Well, it is not just a bit messy, rather, it is completely messy, so much so that it confuses me as well. This is a
    result of copying bits and pieces of code, trying to see what works and what does not, and only after it works, I try to find out why it works. I am still confused with various parts of my own code. In this case, of course, most of the code has been taken from Mayank Gandhi's article.

    never mind you will learn, I'm still learning even at this stage.
    - Thanks for your encouraging words. It is words like these which help me in my determination to keep learning.

    Now, my next and previous links are working. But there are some problems.

    Suppose, I have got a full image by clicking on a previous link of another full image. The following are the details of what I get.


    This ID: 19
    The Filename: 19.jpg
    Its Caption: A traditional lunch
    Which Category: 1
    Next: 20
    Prev: 18
    Array ( [0] => Array ( [now] => 19 [file] => 19.jpg [caption] => A traditional lunch [category] => 1 [next] => 20 [prev] =>
    18 ) ) Categories > pictures_friends
    Now, what is happening is that the picture that is displayed in my full image page belongs to category 1 but I got it by
    clicking the previous link in my third category which is picture_friends (category 3). It states Category 1 in the 3rd line but the Category below (the link in the last line, next to the Categories link) is displaying the name of my third category.
    Now when I click on the next link in the above page, I am taken to the page containing the following details.

    This ID: 20
    The Filename: 20.jpg
    Its Caption: School Friends
    Which Category: 3
    Next: 21
    Prev: 19
    Array ( [0] => Array ( [now] => 20 [file] => 20.jpg [caption] => School Friends [category] => 3 [next] => 21 [prev] => 19 ) )
    Categories > Family Photos
    Now the image in the page with the above details belongs to category 3 but the name 'Family Photos' indicates my first category ie category 1. Why are the names of the categories getting mixed up sometimes?

    When I go the relevant pictures by clicking on the thumbnails on my category page, I get the correct category id displayed in both the places.

    I noticed the following;

    The category id is displayed correctly in the page. But it is the category name which is getting mixed up. The category id for the wrong category name is what is getting displayed in the address bar as well. I am going wrong somewhere but I cannot make out where.

    My full code is like this.

    PHP Code:
    <?php
     
    include("config.inc.php");
     
     
    // initialization
     
    $result_array = array();
     
    $counter 0;
     
    $cid = (int)($_GET['cid']);
     
    $pid = (int)($_GET['pid']);
     
    // Category Listing
     
    if( empty($cid) && empty($pid) )
     {
      
    $number_of_categories_in_row 4;
      
    $result mysql_query"SELECT c.category_id,c.category_name,COUNT(photo_id)
          FROM gallery_category as c
          LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
          GROUP BY c.category_id" 
    );
      while( 
    $row mysql_fetch_array$result ) )
      {
       
    $result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
     
     
      }
      
    mysql_free_result$result ); 
      
    $result_final "<tr>\n";
      foreach(
    $result_array as $category_link)
      {
       if(
    $counter == $number_of_categories_in_row)
       { 
        
    $counter 1;
        
    $result_final .= "\n</tr>\n<tr>\n";
       }
       else
       
    $counter++;
       
    $result_final .= "\t<td>".$category_link."</td>\n";
      }
      if(
    $counter)
      {
       if(
    $number_of_categories_in_row-$counter)
       
    $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'>&nbsp;</td>\n";
       
    $result_final .= "</tr>";
      }
     }
     
     
    // Thumbnail Listing
     
    else if( $cid && empty( $pid ) )
     {
      
    $number_of_thumbs_in_row 5;
      
    $result mysql_query"SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE 
    photo_category='"
    .addslashes($cid)."'" );
      
    $nr mysql_num_rows$result );
      if( empty( 
    $nr ) )
      {
       
    $result_final "\t<tr><td>No Category found</td></tr>\n";
      }
      else
      {
       while( 
    $row mysql_fetch_array$result ) )
       {
        
    $result_array[] = "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'><img 
    src='"
    .$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /></a>";
       }
       
    mysql_free_result$result ); 
       
    $result_final "<tr>\n";
    "<a href='viewgallery.php?cid=$cid'>$category_name</a></td>\n</tr>\n";
     
       foreach(
    $result_array as $thumbnail_link)
       {
        if(
    $counter == $number_of_thumbs_in_row)
        { 
         
    $counter 1;
         
    $result_final .= "\n</tr>\n<tr>\n";
        }
        else
        
    $counter++;
        
    $result_final .= "\t<td>".$thumbnail_link."</td>\n";
     
       }
     
       if(
    $counter)
       {
        if(
    $number_of_photos_in_row-$counter)
       
    $result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'>&nbsp;</td>\n";
        
    $result_final .= "</tr>";
     
     
     
     
     
     
       }
      }
     }
     
     
     
    // Full Size View of Photo
     
    else if( $pid )
     {
      
    $result mysql_query"SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".$pid."'" );
      list(
    $photo_caption$photo_filename) = mysql_fetch_array$result );
      
    $nr mysql_num_rows$result );
      
    mysql_free_result$result ); 
      if( empty( 
    $nr ) )
      {
       
    $result_final "\t<tr><td>No Photo found</td></tr>\n";
      }
      else
      {
     
       
    $result_final .= "<tr>\n\t<td>
     
                                                              </td>\n</tr>\n"
    ;
     
     
    //Next and Previous Links
    $result mysql_query"SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" );
       list(
    $category_name) = mysql_fetch_array$result );
       
    mysql_free_result$result );
                echo 
    '            <div align="left">Category: '.$category_name.'</div>';
     
     
     
    $everything = array();
    $all mysql_query("SELECT min(photo_id) AS First
                            , min(photo_caption) AS Cap
                            , min(photo_filename) AS File
                            , min(photo_category) AS Cate
                            , ( SELECT max(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id < '"
    .$pid."' ) as Prev 
                            , ( SELECT min(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id > '"
    .$pid."' ) as Next
                          FROM gallery_photos
                          WHERE photo_id = '"
    .$pid."'
                          ORDER BY photo_id ASC"
    ); 
             while(
    $list mysql_fetch_array$all ))    {
        
    $everything[] = array('now' => $list['First'], 'file' => $list['File'], 'caption' => $list['Cap'],'category' => $list
    ['Cate'], 'next' => $list['Next'], 'prev' => $list['Prev']);
    }             
     
    mysql_free_result$all );                          
     
                echo 
    '        <table width="490" border="0" cellpadding="0" cellspacing="0">';
                echo 
    '            <tr>';
    foreach(
    $everything as $s => $sval)    {
     
    // if next is set display link
    if(isset($sval['next'])&$sval['category']) {
    $next '<div align="left"> <a href="viewgallery.php?cid='.$sval['category'].'&pid='.$sval['next'].'">Next</a></div>';
        }
    // if prev is set display link
        
    if(isset($sval['prev'])) {
            
    $prev '<div align="left"> <a href="viewgallery.php?cid='.$sval['category'].'&pid='.$sval
    ['prev'].'">Prev</a></div>';
        }
     
     
     
                echo 
    '            <div align="left">'.$sval['caption'].'</div>';
                echo 
    '            <div align="left">Category: '.$sval['category'].'</div>';
     
     
     echo 
    $next;
                echo 
    $prev;
    }
                echo 
    '    </tr>';
                echo 
    '</table>';
                echo 
    "\n"
     
     
     
    $result_final .= "<tr>\n\t<td align='center'>
         <br />
         <img src='"
    .$images_dir."/".$photo_filename."' border='0' width= '550'  
    alt='"
    .$photo_caption."' />
         <br />
         
    $photo_caption
         </td>
         </tr>"
    ;
      }
     }
     
     
    // Final Output
    echo <<<__HTML_END
     
    <html>
    <head>
     <title>Gallery View</title>
    </head>
    <body>
    <table width='100%' border='0' align='center' style='width: 100%;'>
    $result_final  
    </table>
    </body>
    </html>
    __HTML_END;
    ?>
    Also, why should I give the minimum id on the first line? Is it only for testing purposes?

    When I click on the next and previous links, I want the links to pertain to that particular category only. So, when I
    am on the last image of category 1, I should not have a next link, whereas, here, I still have the link to an image in the next code. It is not always like that either. The next links are appearing in the order of the photo ids (pid).

    In order that the photos contain the next link only if it belonged to that particular category, I tried writing the code like this:
    // if next is set display link
    PHP Code:
    if(isset($sval['next'])&$sval['category']) {
    $next '<div align="left"> <a href="viewgallery.php?cid='.$sval['category'].'&pid='.$sval['next'].'">Next</a> 
    but that does not seem to help and I am obviously doing it wrong. I tried doing that before the previous category, but found that the next and previous links disappeared from the images in category 2. I do not understand what is happening.

    I am really sorry for these silly newbie (I do not know when I can stop calling myself that) questions? I also hope my
    questions are clear enough.

  16. #666
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

    Smile

    Quote Originally Posted by jppp View Post
    I am really sorry for these silly newbie (I do not know when I can stop calling myself that) questions? I also hope my
    questions are clear enough.
    First of all, do not feel sorry asking questions no matter how small they are, we have all been their before, believe me.

    Anyway, back to your problem. You need to add a tiny bit of code here and there.

    This:
    Code:
    AND photo_category = '".$cid."'
    First find the line that looks like this:
    PHP Code:
    // Full Size View of Photo
    ....
      
    $result mysql_query"SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".$pid."' "); 
    Now change it to this:
    PHP Code:
    // Full Size View of Photo
    ....
      
    $result mysql_query"SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".$pid."' AND photo_category = '".$cid."' "); 
    The next one is for the code that I wrote, the MySQL query.

    So look for:
    PHP Code:
    $all mysql_query("SELECT min(photo_id) AS First
                            , min(photo_caption) AS Cap
                            , min(photo_filename) AS File
                            , min(photo_category) AS Cate
                            , ( SELECT max(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id < '"
    .$pid."' ) as Prev 
                            , ( SELECT min(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id > '"
    .$pid."' ) as Next
                          FROM gallery_photos
                          WHERE photo_id = '"
    .$pid."'
                          ORDER BY photo_id ASC"
    ); 
    Then change it to this:
    PHP Code:
    $all mysql_query("SELECT min(photo_id) AS First
                            , min(photo_caption) AS Cap
                            , min(photo_filename) AS File
                            , min(photo_category) AS Cate
                            , ( SELECT max(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id < '"
    .$pid."' 
                                  AND photo_category = '"
    .$cid."' ) as Prev 
                            , ( SELECT min(photo_id)
                                   FROM gallery_photos
                                  WHERE photo_id > '"
    .$pid."' 
                                  AND photo_category = '"
    .$cid."' ) as Next
                          FROM gallery_photos
                          WHERE photo_id = '"
    .$pid."'
                               AND photo_category = '"
    .$cid."'
                          ORDER BY photo_id ASC"
    ); 
    What was happening, the photo_id was only being sent and not the category id (photo_category). So when the photo was displayed with the next and previous links the MySQL query would look for the next photo_id. Because of this the next photo (any) would be displayed. But now with that aditional bit of code it will tell the MySQL query to look for the same category for the next or previous photo/image to be displayed.

    Click here for an example to view it in action.

    spence

  17. #667
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Spence, I don’t have enough words to thank you. I had been struggling for such a long time, trying to get the Next and |Previous links to work. I got very depressed and had decided that if I am not able to get the Next and Previous links working by the end of this year, I would try and download one of the galleries like Coppermine or Gallery. But now I am determined to go ahead.

    The code works very well. I am able to get the Next and Previous links working perfectly. I have a small doubt. In each of my categories (I have 4 in all), the first image contains only the Next link and the last image, only the Previous link (Just as it should work). There is something strange happening in one of my categories (Category 3). It contains 6 pictures. Now the photos do not appear as thumbnails in order. What I mean is that in all the other categories, the photos appear in order of their photo ids. In this particular category, the photo with the lowest id is the second in order So, when I click on the first photo of Category 3, I am led to full photo containing a next and a previous link. When I click on the Previous link, I am led to the previous photo which is actually the second photo in the list of thumbnails. When I click on the second photo from the thumbnail page, the photo of course contains only a Next link since it is the photo with the lowest photo id in that particular category. Why is this happening with this particular category only? Of course, I have the option of deleting the 2 photos and then uploading them again. But I was wondering why this happened and whether there is anything I can learn from it.

    Thank you once again. I have learnt a lot from Mayank’s code and this thread I have learnt how to upload and delete photos and have now learnt how to have a next and previous links within a category. I have a lot more to learn (how to add and edit categories, have the same photo in more than one category), how to have a pagination script if there are many photos in one category. I think most of it has been convered in this forum and I am going ahead with my learning process. I will be unfair not only to myself but also to my Sitepoint friends if I give up.

  18. #668
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I'm glad to be some assistance and also to hear you are not giving up. Do take breaks, it helps and any problems please post in this thread or start a new one. As you know, SPF has a number of php programers who are willing to help, so don't be shy asking.

    Starnge to hear you are having problems with category 3. Is that category in a table of it's own? If so, is their something different from the other three?

    spence

  19. #669
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, the category 3 is the same as the other categories. I really did not understand why I was facing that problem. I have now just deleted the second photo in that category (the one that was appearing as the first thumbnail) and the remaining thumbnails are now in order and all the links are working perfectly.

  20. #670
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Getting this error when i try to upload
    Code:
    Warning: copy(http://www.XXX.info/photos/34.jpg) [function.copy]: failed to open stream: HTTP wrapper does not support writeable connections in /home/content/f/o/m/XXX/html/admin/upload.php on line 52
    
    Warning: getimagesize(http://www.XXX.info/photos/34.jpg) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/content/f/o/m/XXX/html/admin/upload.php on line 56
    
    Warning: Division by zero in /home/content/f/o/m/XXX/html/admin/upload.php on line 76
    
    Warning: imagecreatefromjpeg(http://www.XXX.XXX/photos/34.jpg) [function.imagecreatefromjpeg]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/content/f/o/m/XXX/html/admin/upload.php on line 91
    
    Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/content/f/o/m/XXX/html/admin/upload.php on line 102
    
    Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/content/f/o/m/XXX/html/admin/upload.php on line 103

  21. #671
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check your file permissioms.

  22. #672
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have set my photos directory to 777

    What else am i missing ?

  23. #673
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the user that the file being created in that of the webserver ie www-data.www-data for apache (normally) or is it of your account on the system.

    Generally it is better to have the folder that images are being written to set to that of the webserver. This way you will not have issues with file permissions.

    Also you could add some error checking such as doing

    PHP Code:

    echo "<pre>The folder path is: ".$folder_path."</pre>";

    if (!
    file_exists($folder_path))
    {
      echo 
    "<pre>folder ".$folder_path." does not exist!</pre>\n";
    }

    if (!
    is_readable($folder_path))
    {
      echo 
    "<pre>folder ".$folder_path." not readable!</pre>\n";
    }

    if (!
    is_writable($folder_path))
    {
      echo 
    "<pre>folder ".$folder_path." not writable!</pre>\n";

    Last edited by noddy; Nov 17, 2008 at 02:27. Reason: added line breaks

  24. #674
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is on the server itself

    ive used http://www.xxx.info/photos in the config for the database name.

    Did not use the path,

    This worked on my host but this godaddy is errr

  25. #675
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok i used your code and got this

    folder does not exist!folder not readable!folder not writable!


Bookmarks

Posting Permissions

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