Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    Need some ideas to help me build a simple photo gallery.

    Hello,
    As part of my website I want to allow members to upload a limited number of images that they can use in building their pages ( within the website ).

    Each image will be uploaded and re-sampled to ensure it really is an image and to get it to the correct size.

    This is a snippet of what I am using:

    PHP Code:
    imagecopyresampled($N_image$o_im0000$t_wd$t_ht$o_wd$o_ht); 
    $destination $_SERVER['DOCUMENT_ROOT']."/im/mem_images/$N_pix_n"
    Now the problem I have is about updating their file.

    Each time they add photos they will be able to select up to six photos from their computer to upload. This will be in the form.

    So I need to be able to update their image table with these six new photos until they reach the end of the file.

    I will also have to allow them to replace these images and to view them.

    If I want to allow sixty ( 60 ) images then I guess that my sql database
    will need a user id field and sixty image name fields

    like this:

    PHP Code:
    $sql "CREATE TABLE `client_pics` (
       `user_id` varchar(25) NOT NULL default '',
       `pict_01` varchar(40) NOT NULL default '',
       `pict_02` varchar(40) NOT NULL default '',
       `pict_03` varchar(40) NOT NULL default '',
    ...
       `pict_60` varchar(40) NOT NULL default '',
        PRIMARY KEY (user_id)

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1"
    ;


    $result mysql_query($sql)
        or die(
    "could not CREATE client_pics."mysql_error()); 

    Now my question is this:
    When I am updating this table, what is the best way to find the last
    filled up field and continue on from there ?

    I will use something like this to add the new files:

    PHP Code:
     $sql "UPDATE client_pics SET 
             image1 = '$N_pix1',
             image2 = '$N_pix2',
             image3 = '$N_pix3',
             image4 = '$N_pix4',
             image5 = '$N_pix5',
             image6 = '$N_pix6'
                                                 
             WHERE user_id = '$ad_ref' "
    ;
        
             
    mysql_query($sql)
            or die(
    "could not execute $section UPDATE PICTURES query"); 
    Now again - you see my problem - I want to update
    six of the image fields, but I don't know which ones.

    The above will only work for the first time they run the script.

    Any ideas on how I can write this ?
    Thanks
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Don't use 60 columns in your MySQL.
    Simply use 1 row for each photo.

    If the user has some sort of ID, name, email ... something
    to identify them, you can simply count how many rows
    are assigned to that user. That's much easier to do, and
    maintain than a row with 60 columns.

    So a row in your table would look something like ....

    Auto Increment Record No. | User ID | photo.jpg | photo title | photo caption | timestamp |

    Count how many the person has:
    PHP Code:
    $query "SELECT * FROM client_pics WHERE user_id LIKE '$ad_ref'";
    $result mysql_query($query) or die(mysql_error());
    // How many rows did you find for that user?
    $num_rows mysql_num_rows($result);

    if(
    $num_rows 60){
    //OK to add ...
    // add another photo

    Adding photos is easy too .... just add another record (row).

    This will also be important for the user to sort them, edit them, etc.
    And easier for the admin to work with ALL of the photos for all users.

    You can let them upload as they desire, and give a warning after 60 photos,
    then don't let them upload any more. If they have ended up loading 63 photos,
    no big deal ... just cut them off after 60 and before 70. They can then go
    into their profile page and view them all, edit them, delete them, etc.
    Last edited by mlseim; 03-02-2009 at 01:21 PM.

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks for your reply.

    So I will just have this:

    PHP Code:
    $sql "CREATE TABLE `client_pics` (
       `user_id` varchar(25) NOT NULL default '',
       `pict_name` varchar(40) NOT NULL default ''

        PRIMARY KEY (user_id)

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1"
    ;


    $result mysql_query($sql)
        or die(
    "could not CREATE client_pics."mysql_error()); 
    And then count them ?
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    yes ... (I made an edit on the post above just before you submitted your post)

    I mean no ... you are not creating a new table, you are inserting into an existing table ...

    Sort of like this (but I don't know the names of your variables ...) ...

    mysql_query("INSERT INTO client_pics (user_id, pict_name) VALUES('$userid, $filename') ")or die(mysql_error());
    Last edited by mlseim; 03-02-2009 at 01:26 PM.

  • Users who have thanked mlseim for this post:

    jeddi (03-02-2009)

  • #5
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks -
    these edits are funny things
    - they make you think you didn't read it properly
    the first time ( going mad ) !!!

    Anyway
    why do you use LIKE and not "=" iin the query.

    Also whats the best way to do this six times :

    for each $N_pix1 ( 1 - 6 )
    mysql_query("INSERT INTO client_pics (user_id, pict_name) VALUES('$userid, $filename') ")or die(mysql_error());


    Thanks for your help - it makes a lot of sense
    Last edited by jeddi; 03-02-2009 at 01:48 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I suggest you use Google to find some MySQL tutorials.
    You can learn it all for free (without buying any books).

    You could use = (I just used LIKE for pattern match, no reason why).

    It's too hard to provide any examples, because with MySQL, we would
    need access to all files and scripts. No idea on your MySQL structure,
    the variables you use, the forms you use ... not enough information.

  • #7
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thats OK

    I sorted it out now.


  •  

    Posting Permissions

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