Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-02-2009, 09:26 AM   PM User | #1
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,544
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
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.
jeddi is offline   Reply With Quote
Old 03-02-2009, 01:10 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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..
mlseim is offline   Reply With Quote
Old 03-02-2009, 01:20 PM   PM User | #3
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,544
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
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.
jeddi is offline   Reply With Quote
Old 03-02-2009, 01:22 PM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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..
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
jeddi (03-02-2009)
Old 03-02-2009, 01:28 PM   PM User | #5
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,544
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
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
__________________
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.

Last edited by jeddi; 03-02-2009 at 01:48 PM..
jeddi is offline   Reply With Quote
Old 03-02-2009, 01:48 PM   PM User | #6
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Old 03-02-2009, 01:58 PM   PM User | #7
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,544
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
Thats OK

I sorted it out now.
jeddi is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:48 PM.


Advertisement
Log in to turn off these ads.