SitePoint Sponsor

User Tag List

Page 17 of 31 FirstFirst ... 713141516171819202127 ... LastLast
Results 401 to 425 of 767
  1. #401
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Morristown, TN
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jj67
    1) I would like to show 10 photos by page and make a navigation for thumbnails in each category (whith links NEXT and PREVIOUS).
    2) Limit the size of uploaded photos (for exemple, each photo not bigger than 300Ko).

    Anyone knows how to do that?
    Have you read the entire thread? We have done navigation several pages ago and we have also limited the picture size by pixels (ex: 400 x 600 ) That would effectively limit the filesize. Try the downloadable version by drewf, it might contain everything you need.

  2. #402
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    animal777,

    I have seen the pages wfere you have done the navigation. The problem is that the link to see your code (http://www.anglersforchrist.com/gallery/viewgallery.txt) is no more activated... Can you show me php code so I can understand the way you made it work ?

    Thanks

  3. #403
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    animal777,

    I have put your code in my page and I have the same problem that drewf had. I have the link "NEXT" on ma page, but when I click on it the next page is not displayed...
    I saw that you have proposed to drewf some other code. Could you show me ?

  4. #404
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Morristown, TN
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jj67
    animal777,

    I have put your code in my page and I have the same problem that drewf had. I have the link "NEXT" on ma page, but when I click on it the next page is not displayed...
    I saw that you have proposed to drewf some other code. Could you show me ?
    Sorry, The owner of that website switched hosts and I am no longer working on it. I am attaching the txt files of my code.
    Attached Files Attached Files

  5. #405
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi together, fantastic script ! :-)

    how to rewrite the following code to get the last image of each category, because im not familar with left join statements

    $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" );

    i want to show a thumbnail between every category on the listing page
    hope you can help me

    thx in advance

  6. #406
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by animal777
    Sorry, The owner of that website switched hosts and I am no longer working on it. I am attaching the txt files of my code.

    Thanks, animal777 ! I will try it.

  7. #407
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by animal777
    Sorry, The owner of that website switched hosts and I am no longer working on it. I am attaching the txt files of my code.
    animal777,
    The navigation works! Thanks one more time.

  8. #408
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Hi there all. I stumbled upon this tutorial and it's awesome, thanks very much.

    I have a backend system that I would like to integrate this into but have had several problems. (All code below)

    - I coded a page to add, edit and delete catagories...it isn't working.
    - I would like to add functions to edit and delete images...I, however, do not know how to implement these functions properly.

    I am farely new to PHP but have a basic idea of how it all works.

    Add, edit, delete catagories page code (admin_photocat.php):
    PHP Code:
    <?
    $root 
    './../';
    $act $_GET['act'];
    if(
    $act == 'add' || empty($act) || $act == '')
    {
        
    //Setup page
        
    $pagename 'Add Photo Catagory';
        include(
    $root 'admin/admin_header.php');
        
    //Begin handling the form.
        
    $username = (isset($_SESSION['username'])) ? $_SESSION['username'] : '';
        if(
    $_POST['submit'])
        {
            
    $sql 'LOCK TABLES gallery_catagory WRITE';
            
    $db->query($sql);
            
    $sql 'INSERT INTO gallery_catagory (`catagory_id`,`catagory_name`) VALUES (\'' $_POST['catagory_id'] . '\', NOW(), \'' $_POST['catagory_name'] . '\')';
            
    $result $db->query($sql);
            if(
    $result)
            {
                
    $message 'Your catagory has been added successfully to your site.';
            }
            
    $sql 'UNLOCK TABLES';
            
    $db->query($sql);
        }
        
    ?>
        <form action="<? $PHP_SELF ?>" method="post">
            <p>
                <?=(isset($message)) ? $message '';?>
            </p>
    <p>
            <h3>Add Photo Catagory</h3>
        </p>
            <p>
    <form name="add_category" action="admin_photocat.php" method="post"> 


    Name: <input type="text" name="cname" /><BR><BR>
    <input type="submit" value=">>Add Catagory<<" name="action" /><input type="reset" value="Reset Form" name="reset" />  

    </form> 
    </p>
                


        <?
    }
    elseif(
    $act == 'edit')
    {
        
    //Setup page
        
    $pagename 'Edit Photo Catagory';
        include(
    $root 'admin/admin_header.php');
        
    //Begin handling the form.
        
    $username = (isset($_SESSION['username'])) ? $_SESSION['username'] : '';
        if(!
    $_GET['catagory_id'])
        {
        
    ?>
        <p>
            <h3>Edit Photo Catagory</h3>
        </p>
        <p>
            Select a photo catagory to edit.
        </p>
        <?
            $result 
    $db->query('SELECT * FROM `gallery_catagory` ORDER BY `catagory_id` DESC');
            while(
    $rows $db->fetchrow($result))
            {
                echo 
    '<a href="admin_photocat.php?act=edit&id=' $rows['catagory_id'] . '">' $rows['catagory_name'] . '</a><BR>';
            }
        }
        else
        {
            if(
    $_POST['submit'])
            {
                
    $sql 'UPDATE `gallery_catagory` SET `catagory_name` = \'' $_POST['catagory_name'] . '\'; WHERE `catagory_id` = \'' $_GET['catagory_id'] . '\'';
                
    $result $db->query($sql);
                if(
    $result)
                {
                    
    $message 'Your photo catagory has been edited successfully.';
                }
            }
                
    $sql 'SELECT * FROM `gallery_catagory` WHERE `catagory_id` = \'' $_GET['catagory_catagory_id'] . '\'';
                
    $result $db->query($sql);
                
    $news $db->fetchrow($result);
                
    $title $news['catagory_name'];
            
    ?>
            <form action="<? $PHP_SELF ?>" method="post">
                <p>
                    <?=(isset($message)) ? $message '';?>
                </p>
                <p>
                    Name: <input type="text" accept="text/html" name="catagory_name" value="<?=$news['catagory_name']?>" /><Br />
                    </p>
                <p>
                    <input type="hidden" name="author" value="<?=$_SESSION['username']?>" />
                </p>
                <p>
                    <input type="submit" name="submit" class="blink" value=">>Edit Photo Catagory<<" /> | <input type="reset" name="reset" value="Reset Form" />
                </p>
            </form>
        <?
        
    }
    }
    elseif(
    $act == 'delete')
    {
        
    //Setup page
        
    $pagename 'Delete Photo Catagory';
        include(
    $root 'admin/admin_header.php');
        
    //Begin handling the form.
        
    $catagory_id $_GET['catagory_id'];
        if(
    $catagory_id)
        {
            
    $sql 'DELETE FROM `gallery_catagory` WHERE `catagory_id` = \'' $_GET['catagory_id'] . '\'';
            
    $result $db->query($sql);
            if(
    $result)
            {
                
    $message 'The catagory has been deleted.';
                echo 
    $message;
            }
            else
            {
                
    $message mysql_error();
                echo 
    $message;
            }
        }
        else
        {
            
    $sql 'SELECT * FROM `gallery_catagory` ORDER BY `catagory_id` DESC';
            
    $result $db->query($sql);
            
    ?>
            <p>
                <h3>Delete Photo Catagory</h3>
            </p>
            <p>
                Select a photo catagory to delete. This <b><i>cannot</i></b> be undone!
            </p>
            <p>
            <?
            
    while($news $db->fetchrow($result))
            {
                
    $title $news['title'];
                
    $catagory_id $news['catagory_id'];
                echo 
    '<BR />';
                echo 
    '<a href="admin_photocat.php?act=delete&id=' $catagory_id '">' $catagory_name '</a>';
            }

        }
    }
    ?>
    <?php 

    else 

    if( 
    strcasecmp($_POST['action'], "add")==&& !empty( $_POST['cname'] ) ) 

    add_category($_POST['cname']); 

    else if( 
    strcasecmp($_POST['action'], "edit")==&& !empty( $_POST['cname'] ) && !empty( $_POST['categoryid'] ) ) 

    edit_category($_POST['categoryid'], $_POST['cname']); 

    else if( 
    strcasecmp($_POST['action'], "delete")==&& !empty( $_POST['categoryid'] ) ) 

    delete_category($_POST['categoryid']); 

    else 

    echo(
    "Action not understood"); exit; 


    echo(
    "Process completed!");
    echo(
    "<a href="index.php">Back To Admin Home</a>"); 



    // the functions here 

    function edit_category($category_id$new_name

    mysql_query(
    UPDATE gallery_category SET 
    category_name = '" 
    addslashes($new_name) . "' 
    WHERE category_id = '" 
    addslashes($category_id) . "'"); 

    function 
    add_category($category_name

    mysql_query(
    INSERT INTO gallery_category ( 
    category_name 
    ) VALUES ( 
    '" 
    addslashes($category_name) . "' 
    )"
    ); 


    function 
    delete_category($category_id

    global 
    $images_dir

    $result mysql_query(
    SELECT photo_filename 
    FROM gallery_photo 
    WHERE photo_category='" 
    addslashes($category_id) . "'"); 
    while (
    $row = @mysql_fetch_array($result)) { 
    unlink($images_dir '/' $row[0]); 


    mysql_query(
    DELETE FROM gallery_photo 
    WHERE photo_category='" 
    addslashes($category_id) . "'"); 

    mysql_query(
    DELETE FROM gallery_category 
    WHERE category_id='" 
    addslashes($category_id) . "'"); 

    include (
    "admin_footer.php");
    ?>
    Can anyone also please help me with implementing an edit and delete function for the photos themselves?

    Thanks in advance,
    disfunktion.

  9. #409
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Morristown, TN
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by disfunktion
    Hi there all. I stumbled upon this tutorial and it's awesome, thanks very much.

    Can anyone also please help me with implementing an edit and delete function for the photos themselves?
    I am attaching my admin code // it should do all the stuff you want.
    Attached Files Attached Files

  10. #410
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a great tutorial, and the forum thread has been a great help to me whilst trying to get it all working. I do have one small question though. It's probably something that those of you with PHP / MySQL knowledge think is simple, I just can't seem to get my head round it.

    Is there any way at all to get the categories to list themselves on the screen in alphabetical order, without loading them up in that order yourself? I'm hoping to have a gallery online in alphabetical, but will be adding topics later on - which will add to the end of the list, rather than in correct order.

    Can anybody help? Is there some 'command' I should be calling when it displays the page? Thanks in advance!

  11. #411
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by btwentythree
    how to rewrite the following code to get the last image of each category,
    Just add an
    Code:
    ORDER BY DESC
    LIMIT 1
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  12. #412
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by antonylast
    Is there any way at all to get the categories to list themselves on the screen in alphabetical order,
    Code:
    ORDER BY category_name
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  13. #413
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please can any one help. I am very new to php and would like to list all the id and photo on the admin page under the delete photo section, to allow the user to reference the photo the would like to edit.
    I have tried but it not working
    <?
    echo "Current Photo Listbr><br>";
    $result_id = mysql_query("SELECT photoid FROM gallery_photo");
    if (!$result_id) {
    echo("<P>Error performing query: " .
    mysql_error() . "</P>");
    exit();
    }
    echo(" <table width='90%' border='0' align='center' cellpadding='2'>
    <tr>
    <td width='11%'>Photo ID</td>
    <td width='26%'>Photo</td>
    <td width='63%'>Caption</td>
    </tr> ");

    while ($row = mysql_fetch_array($result_id)) {
    echo("<tr><td>" . $row['photo_id'] . " </td> ");
    }

    $result_pic = mysql_query("SELECT photo_filename FROM gallery_photo");
    if (!$result_pic) {
    echo("<P>Error performing query: " .
    mysql_error() . "</P>");
    exit();
    }
    while ($row = mysql_fetch_array($result_pic)) {
    echo("<td><img name='' src='photos/ " . $row['photo_filename'] . " ' /> </td> ");
    }

    $result_cap = mysql_query("SELECT photo_caption FROM gallery_photo");
    if (!$result_cap) {
    echo("<P>Error performing query: " .
    mysql_error() . "</P>");
    exit();
    }
    while ($row = mysql_fetch_array($result_cap)) {
    echo("<td>" . $row['photo_caption'] . "</td>");

    echo("</tr></table>");

    ?>

  14. #414
    SitePoint Zealot
    Join Date
    Aug 2002
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you mean "list the photo id and picture [caption? name?]..."

    PHP Code:
     
    // The basic SELECT statement
    $select = " SELECT photo_category, photo_id, photo_filename, photo2_id, photo_caption, photo_price "; parents.NAME, parents.EMAIL, parents.PHONE, parents.ACTIVE, parents.REMINDER";
    $from = " FROM gallery_photos";
    $order = " ORDER by photo_id desc ";
    ?>
    <br />
    <table width="100%"border="1">
            <tr> 
        <th><font face="Arial, Helvetica, sans-serif">Category</font></th>
        <th><font face="Arial, Helvetica, sans-serif">Photo ID</font></th>
             <th><font face="Arial, Helvetica, sans-serif">Trans File Name</font></th>
             <th><font face="Arial, Helvetica, sans-serif">Trans Caption</font></th>
        <th><font face="Arial, Helvetica, sans-serif">Trans Thumb</font></th>
             <th><font face="Arial, Helvetica, sans-serif">Price</font></th>
        <th><font face="Arial, Helvetica, sans-serif">In Use Photo ID</font></th>
             <th><font face="Arial, Helvetica, sans-serif">In Use File Name</font></th>
        <th><font face="Arial, Helvetica, sans-serif">In Use Caption</font></th>
             <th><font face="Arial, Helvetica, sans-serif">In Use Thumb</font></th>
        <th><font face="Arial, Helvetica, sans-serif">Options</font></th>
     
            </tr>
            <?php
     
    $result 
    mysql_query($select $from $where $order); 
     
    if (!
    $result) {         
    echo(
    "</table>");
    echo(
    "<p>Error retrieving data from database!<br />".
         
    "Error: " mysql_error() . "</p>");
    exit();
    }
     
    //while loop, will run through all rows that 
    //have been fetched 
    while($row=mysql_fetch_array($result)) { 
        
    //put $row stuff into workable variables 
        
    $category $row["photo_category"];
    $photo_id $row["photo_id"]; 
        
    $photo_filename $row["photo_filename"]; 
    $photo_caption $row["photo_caption"]; 
    //Thransparency Thumbnail
    $photo_price $row["photo_price"]; 
    //in-use stuff
    $photo2_id $row["photo2_id"]; 
     
    //In-Use Thumbnail
     
     
    /*******************************************************
    *                                                                                                 *
    *                                                                                                 *
    * sitepoint thread: ignore this part, i combined two galleries for this user        *
    *                                                                                                 *
    *                                                                                                 *
    *******************************************************/
     
    //get photo2 data
    $result2 mysql_query(" SELECT photo_id2, photo_filename2, photo_caption2 FROM gallery_photos2 WHERE photo_id2=$photo2_id ");
    if (!
    $result2) {         
    echo(
    "</table>");
    echo(
    "<p>Error retrieving data from database!<br />".
         
    "Error: " mysql_error() . "</p>");
    exit();
    }
     
    $row2 mysql_fetch_array($result2);
     
    $photo_id2 $row2["photo_id2"]; 
    $photo_filename2 $row2["photo_filename2"];
    $photo_caption2 $row2["photo_caption2"]; 
     
    if (!
    $photo_caption2) {
    $photo_caption2 "<i>empty</i>";
    }
     
    $result3 mysql_query(" SELECT * from gallery_category WHERE category_id= $category ");
    $row3 mysql_fetch_array($result3);
     
    $category $row3["category_name"];
     
    /*******************************************************
    *                                                                                                 *
    *                                                                                                 *
    * sitepoint thread: end - "ignore this...",                                             *
    *                                                                                                 *
    *                                                                                                 *
    *******************************************************/
     
     
            //echo the options out... 
        
    echo(
        <tr> 
         <td align=\"center\">
    $category</td>\n
    <td align=\"center\">
    $photo_id</td>\n
    <td align=\"center\">
    $photo_filename</td>\n
    <td align=\"center\">
    $photo_caption</td>\n
    <td align=\"center\"><img src=\"/manage/photos/tb_
    $photo_id.jpg\"></td>\n
    <td align=\"center\">$ 
    $photo_price</td>\n
    <td align=\"center\">
    $photo_id2</td>\n
    <td align=\"center\">
    $photo_filename2</td>\n
    <td align=\"center\">
    $photo_caption2</td>\n
    <td align=\"center\"><img src=\"/manage/photos/tb_
    $photo_filename2\"></td>
     
        <td align=\"center\">[<a href='edititem.php?id=
    $photo_id'>Edit</a> .         
             <a href=\"delitem.php?id=
    $photo_id\" onClick=\"return confirm('Are you sure you want to delete this parent account with id# $photo_id ??')\">Delete</a>]</td>\n 
     
        </tr>"
    ); 
    //loop 
    }
    ends up looking like the attachment...
    Attached Images Attached Images

  15. #415
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hakalugi
    do you mean "list the photo id and picture [caption? name?]..."

    PHP Code:
     
    // The basic SELECT statement
    $select = " SELECT photo_category, photo_id, photo_filename, photo2_id, photo_caption, photo_price "; parents.NAME, parents.EMAIL, parents.PHONE, parents.ACTIVE, parents.REMINDER";
    $from = " FROM gallery_photos";
    $order = " ORDER by photo_id desc ";
    ?>
    <br />
    <table width="100%"border="1">
            <tr> 
        <th><font face="Arial, Helvetica, sans-serif">Category</font></th>
        <th><font face="Arial, Helvetica, sans-serif">Photo ID</font></th>
             <th><font face="Arial, Helvetica, sans-serif">Trans File Name</font></th>
             <th><font face="Arial, Helvetica, sans-serif">Trans Caption</font></th>
        <th><font face="Arial, Helvetica, sans-serif">Trans Thumb</font></th>
             <th><font face="Arial, Helvetica, sans-serif">Price</font></th>
        <th><font face="Arial, Helvetica, sans-serif">In Use Photo ID</font></th>
             <th><font face="Arial, Helvetica, sans-serif">In Use File Name</font></th>
        <th><font face="Arial, Helvetica, sans-serif">In Use Caption</font></th>
             <th><font face="Arial, Helvetica, sans-serif">In Use Thumb</font></th>
        <th><font face="Arial, Helvetica, sans-serif">Options</font></th>
     
            </tr>
            <?php
     
    $result 
    mysql_query($select $from $where $order); 
     
    if (!
    $result) {         
    echo(
    "</table>");
    echo(
    "<p>Error retrieving data from database!<br />".
         
    "Error: " mysql_error() . "</p>");
    exit();
    }
     
    //while loop, will run through all rows that 
    //have been fetched 
    while($row=mysql_fetch_array($result)) { 
        
    //put $row stuff into workable variables 
        
    $category $row["photo_category"];
    $photo_id $row["photo_id"]; 
        
    $photo_filename $row["photo_filename"]; 
    $photo_caption $row["photo_caption"]; 
    //Thransparency Thumbnail
    $photo_price $row["photo_price"]; 
    //in-use stuff
    $photo2_id $row["photo2_id"]; 
     
    //In-Use Thumbnail
     
     
    /*******************************************************
    *                                                                                                 *
    *                                                                                                 *
    * sitepoint thread: ignore this part, i combined two galleries for this user        *
    *                                                                                                 *
    *                                                                                                 *
    *******************************************************/
     
    //get photo2 data
    $result2 mysql_query(" SELECT photo_id2, photo_filename2, photo_caption2 FROM gallery_photos2 WHERE photo_id2=$photo2_id ");
    if (!
    $result2) {         
    echo(
    "</table>");
    echo(
    "<p>Error retrieving data from database!<br />".
         
    "Error: " mysql_error() . "</p>");
    exit();
    }
     
    $row2 mysql_fetch_array($result2);
     
    $photo_id2 $row2["photo_id2"]; 
    $photo_filename2 $row2["photo_filename2"];
    $photo_caption2 $row2["photo_caption2"]; 
     
    if (!
    $photo_caption2) {
    $photo_caption2 "<i>empty</i>";
    }
     
    $result3 mysql_query(" SELECT * from gallery_category WHERE category_id= $category ");
    $row3 mysql_fetch_array($result3);
     
    $category $row3["category_name"];
     
    /*******************************************************
    *                                                                                                 *
    *                                                                                                 *
    * sitepoint thread: end - "ignore this...",                                             *
    *                                                                                                 *
    *                                                                                                 *
    *******************************************************/
     
     
            //echo the options out... 
        
    echo(
        <tr> 
         <td align=\"center\">
    $category</td>\n
    <td align=\"center\">
    $photo_id</td>\n
    <td align=\"center\">
    $photo_filename</td>\n
    <td align=\"center\">
    $photo_caption</td>\n
    <td align=\"center\"><img src=\"/manage/photos/tb_
    $photo_id.jpg\"></td>\n
    <td align=\"center\">$ 
    $photo_price</td>\n
    <td align=\"center\">
    $photo_id2</td>\n
    <td align=\"center\">
    $photo_filename2</td>\n
    <td align=\"center\">
    $photo_caption2</td>\n
    <td align=\"center\"><img src=\"/manage/photos/tb_
    $photo_filename2\"></td>
     
        <td align=\"center\">[<a href='edititem.php?id=
    $photo_id'>Edit</a> .         
             <a href=\"delitem.php?id=
    $photo_id\" onClick=\"return confirm('Are you sure you want to delete this parent account with id# $photo_id ??')\">Delete</a>]</td>\n 
     
        </tr>"
    ); 
    //loop 
    }
    ends up looking like the attachment...
    Yes thank you for your fast reponse. I will let you know how I get on.

  16. #416
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    upload file to mysql

    I have been searching on how to simultaneously upload multiple files to mysql. Yes, I have a php script to insert 1 file that is why I like this tutorial so I tried modifying to INSERT the files into mysql. I did not want to have files in a directory like this tutorial suggest. Please help. Currently, I can achieve everything correctly, filename, filetype, etc but how to upload the file data itself puzzles me. Thanks you

  17. #417
    SitePoint Zealot
    Join Date
    Aug 2002
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is frowned upon (see blobs)

    but to see how some people do it, go here: http://www.php.net/manual/en/functio...e-blob-add.php

  18. #418
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great Tutorial, mayank!!
    Truly, I had the PHP Gallery tutorial read and the System built in Minutes.
    The forum took a few hours... phew; that's some read.

    Thanks to all the contributors to this project (you know who you are); it was truly monumental see how these types of user suppoted projects can build and become something greater with time (26 months to be exact).

    Well, this has been alot for one day; time for me to eat, rest, and digest the miles of code within this archive.

    Cheers,
    VibeX

  19. #419
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    What a great script

    I did have a problem, though. I could view the thumbnails on the viewpage, but when I clicked the link to view the full size version the photo would not show

    I found that the photos need to be chmod to 644. Then it worked, so I added a bit of code into the upload.php, so every time the photo is uploaded it will set the photo(s) to 644 (chmod).

    Look for the line that says: // Let's get the Thumbnail size

    Now copy and paste this above it:
    PHP Code:
    // Chmod the Original file for user able to view
    chmod($images_dir.'/'.$filename0644); 
    Done.

    Spence
    "Don't you just love it when you solve a programming bug only to create another."

  20. #420
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Great work !!!!

    I m totaly newbie but after some reading and copy/paste im done this ...

    viewgallery.php

    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 2;

            
    $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 1;

            
    $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]."' /> ".$row[1]."</a>"; }
                
    mysql_free_result$result );    

                
    $result_final "<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='".addslashes($pid)."'" );
            list(
    $photo_caption$photo_filename) = mysql_fetch_array$result );
            
    $nr mysql_num_rows$result );
            
    mysql_free_result$result );    

            
    //fill pid_array with sorted pids in current category
            
    $result mysql_query"SELECT photo_id FROM gallery_photos WHERE photo_category='".addslashes($cid)."' ORDER BY photo_id" );
            
    $ct mysql_num_rows$result );    
            while (
    $row mysql_fetch_array($result)) {
                
    $pid_array[] = $row[0];
                 }
            
    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'>Albums</a> &gt;
                            <a href=viewgallery.php?cid=
    $cid'>$category_name</a><br><br></td>\n</tr>\n";
                
                
    // display previous and next links if more than one photo
                
    if ($ct 1) {
                      
    $key array_search($pid$pid_array);
                      
    $prev $key 1;
                      if (
    $prev 0$prev $ct 1;
                      
    $next $key 1;
                      if (
    $next == $ct$next 0;
                      
    $result_final .= "<tr><td colspan='10'><center>";
                      
    $result_final .= "<a href=viewgallery.php?cid=$cid&pid=".$pid_array[$prev]."'>Previous</a>&nbsp;&nbsp;&nbsp;";
                     
    $result_final .= "(".($key+1)." / ".$ct.")&nbsp;&nbsp;&nbsp;";
                      
    $result_final .= "<a href=viewgallery.php?cid=$cid&pid=".$pid_array[$next]."'>Next</a>";
                     
    $result_final .= "</center></td></tr>";
                }
                            
                
    $result_final .= "<tr>\n\t<td align='center'>
                        <img src='"
    .$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' width='500' />
                        <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;
    ?>
    1)
    as you can see i v set..... $number_of_thumbs_in_row = 1;
    but what whapens if there are many thumbs per page???
    how can i paginate them?
    for example every 5/10/15/20 thumbs per page??
    2)
    i want to output some more infos under the final thumbnail ...
    any idea how i can do this ???
    i v try to add my variables here..
    PHP Code:
    $result_final .= "<tr>\n\t<td align='center'>
                        <img src='"
    .$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' width='500' />
                        <br />
                        
    $photo_caption
                        </td>
                        </tr>"

    but the results where .....

    Keep the good work.....in some.. years... maybe i can help you
    Last edited by NTGre; Nov 14, 2005 at 13:54.

  21. #421
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Morristown, TN
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NTGre
    as you can see i v set..... $number_of_thumbs_in_row = 1;
    but what whapens if there are many thumbs per page???
    how can i paginate them?
    for example every 5/10/15/20 thumbs per page??
    Have you read the entire thread? We have discussed these issues before. In fact on this page there are posts by me which contain the pagination code to page between multiple pages of thumbnails.

  22. #422
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Iwas blind...

    Probably i was blind....thnx..

    but i got some more questions

    in preupload.php i v create a new category to allow submit 1more info.

    PHP Code:
    $result mysql_query"SELECT category1_id,category1_name FROM gallery_category1" );
        while( 
    $row mysql_fetch_array$result ) )
        {
    $photo_category1_list .=<<<__HTML_END
        <option value="$row[0]">$row[1]</option>\n
    __HTML_END;
        }
        
    mysql_free_result$result ); 
    in upload.php iv made this

    PHP Code:
    mysql_query"INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_category`,`First`,`Last`, `photo_category1`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."','$First','$Last', '".addslashes($_POST['category1'])."')" ); 
    that is working fine but sends in my database the category1_id and not the name..
    is any way to send the category1_name to my gallery_photos table??

    i think that this way is much easyer to build a search form for my photo gallery.



    Thnx again for your help....

  23. #423
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Hi all,

    I haven't checked to see if this has already been mentioned but I've created a 'Sorry, no photo available' bit to the upload.php file.

    handy if you want to use the script for a public gallery or advertising website.

    edit upload.php and find the line:

    PHP Code:
    while( $counter <= count($photos_uploaded) )
        {
            if(
    $photos_uploaded['size'][$counter] > 0)
            { 
    now copy and paste below above those lines above:

    PHP Code:
    if(empty($_FILES['photo_filename']['size'][$counter]))
    {
                    
    mysql_query"INSERT INTO gallery_photos(photo_id, photo_filename, photo_caption, etc...) VALUES('0', '".addslashes($_POST['photo_filename'])."', '".addslashes($_POST['photo_caption'])."', etc..) ");
                    
    $new_id mysql_insert_id();
                    
    $filetype filetype('images/nophoto.jpg');
                    
    $filename $new_id.".jpg";

                    
    mysql_query"UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );
                                    
                    
    // Store the files
                    
    copy('images/nophoto.jpg'$images_dir.'/'.$filename);
                    
                    
    copy('images/nophotosm.jpg'$images_dir.'/tb_'.$filename);
                            
                    
    $result_final .= "<img src='".$images_dir."/tb_".$filename."' /><br />"
                    
    $result_final .= "<b>Advert Added with no photo.</b>";
    }
    else

    then at the end of upload.php replace the code '$counter++;' with the code below:

    PHP Code:
        $counter++;
            }
        }
        
    // Print Result
    echo "$result_final";
    ?> 
    now create two .jpg files, one called nophoto.jpg and nophotosm.jpg. these can be different names, but you will have to replace the names in the above code.

    nophoto.jpg = needs to be made to the largest 'Original' size. so mine is 300x300. you can check this in upload.php and look for '// Let's get the Original size'

    below it will be the size settings for the 'Original size'

    nophotosm.jpg = is for the thumbnail. this needs to be made to the size your thumbnails size. mine are 100x100. again you can check to see your settings in upload.php under '// Let's get the Thumbnail size'.

    place both pictures into the 'images' directory where upload.php is kept.

    spence
    "Don't you just love it when you solve a programming bug only to create another."

  24. #424
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Another one for the script is the show the newest photos in the past seven days. If no photos are added then a message will apear saying 'No new photos added'.

    Here's the script, make a new .php file and name it what ever:

    PHP Code:
    <?php
            
    include "config.inc.php";
            
            
    $query_array = array();
            
    $counter 0;
            
            
    $cid = (int)($_GET['cid']);
            
    $pid = (int)($_GET['pid']);

    if( empty( 
    $cid ) && empty( $pid ) )
            {
                    
    $number_of_thumbs_in_row 1;

                    
    $query = @mysql_query"SELECT photo_id, photo_filename, photo_caption, etc.. FROM gallery_photos WHERE DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= photo_date ORDER BY photo_date DESC LIMIT 0, 8");

                    
    $nr = @mysql_num_rows$query );

                    if( empty( 
    $nr ) )
                    {
                            
    $query_final "\t<tr><td><div align=\"center\"><strong><font face='Verdana, Arial, Helvetica, sans-serif' size='1'><span class='main_text'>No new adverts found!</span></font></strong></div></td></tr>\n";
                    }
                    else
                    {
                            while( 
    $row mysql_fetch_array$query ) )
                            {                                
                                    
    $catquery = @mysql_query"SELECT category_name, category_id FROM gallery_category WHERE category_id='".addslashes($row[9])."'" );
                                    list(
    $category_name$category_id) = mysql_fetch_array$catquery );
                                    
    mysql_free_result$catquery );
                            
                                    
    $query_array[] = "<table width='400' border='0' cellspacing='0' cellpadding='0'>
          <tr> 
            <td valign='middle' rowspan='8'>
              <a href='"
    .$home_dir."/index.php?cid=$cid&pid=".$row[0]."'><img src='".$home_dir."/".$images_dir."/tb_".$row[1]."' border='0' alt='".$row[1]."' /></a>
            </td>
            <td width='280' valign='top' bgcolor='#BDC8A4'>Title 
              :</span> 
    $row[2] </td>
          </tr>
            <td valign='top'>Category 
              :</span> <a href='"
    .$home_dir."/index.php?cid=$category_id'>$category_name </a></td>
          </tr>
        </table>
        <hr noshade align='center' size='1' width='400'>
        </td></tr>"
    ;
                            }
                            
    mysql_free_result$query );
                            
                            
    $query_final "<tr><span class='main_text'>New adverts added in the past 7 days</span><br><br>";
     
                            foreach(
    $query_array as $thumbnail_link)
                            {
                                    if(
    $counter == $number_of_thumbs_in_row)
                                    {        
                                            
    $counter 1;
                                    }
                                    else
                                    
    $counter++;
                                    
                                    
    $query_final .= "\t<td><div align=\"center\">".$thumbnail_link."</div></td>\n";
                            }
                    }
                }
    echo 
    "$query_final";
    ?>
    Within the script you may notice 'photo_date'. A new field needs to be added to the gallery_photos table. everytime a person uploads a photo a date needs to be placed into it, formated as this 'yyyy-mm-dd'.

    you can do this with php by adding this to the date field in the form on your html page:
    PHP Code:
    <input type='text' name='photo_date' size='20' value='<? date "Y-m-d"?>' />
    The large 'Y' is to get the full year, e.g. 2005. A small 'y' just gets the year, e.g. 05.

    Then you will need to add this bit into the upload.php file:
    PHP Code:
    photo_date and '".addslashes($_POST['photo_date'])."' 
    where the line starts of with:
    PHP Code:
    mysql_query"INSERT INTO gallery_photos(photo_id, photo_filename, etc... 
    the limit of showing how many thumbnails is set to '8'. this can be changed to what erver you want it to be. just find:
    PHP Code:
    LIMIT 08"); 
    and change it if you wish.

    also, the days to go back is set to '7 days'. this can be changed also. just look for:
    PHP Code:
    INTERVAL 7 DAY 
    and change it to how many days back you want.

    Once done, place this code into the first page where you want the thumbnails to apear:
    PHP Code:
    <? include "./yourfile.php"?>
    This script is basiclly the thumbnail script part, but modified.

    Hope this helps. If i've missed something plaz say

    Spence
    "Don't you just love it when you solve a programming bug only to create another."

  25. #425
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ............

    we use this for gallery_category

    PHP Code:
    $result mysql_query"SELECT category_id,category_name FROM gallery_category" );
        while( 
    $row mysql_fetch_array$result ) )
        {
    $photo_category_list .=<<<__HTML_END
        <option value="$row[0]">$row[1]</option>\n
    __HTML_END; 
    but this is insert in the database only the category_id and is number(1,2,3...)

    i want to create a new field in my gallery_photos named "gerne" for examle and
    i want to post there the category_name(rock,or Jazz for examle) and not the category_id
    how i can do this using the same list/menu????


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
  •