RE: [PHP-DB] Previous | Next (Again)

2001-08-31 Thread Jeff Oien

OK, I see what you're saying and the O'Reilly link from someone
else was very helpful, however I think there still must be a simpler way to
do it. I don't need to have the reorder picture function. Each picture record
has an id field which is linked to their username (in another table) and a photo_id
which is unique for every photo in the database. What if I selected all the photo_ids
for a particular user and put them in an array and also counted them (the total).
Then the array would have photo_id[0], photo_id[1] etc. When the page is
displayed, I could somehow find out which number of the array the current
photo is and make it +1 to get the number of the order starting with 1. Then
for the Next page, it would display the photo_id[] +1. That was hard to explain
I hope it made sense.

Do you think this would work? If so, how do I loop through the photo_id column
and put them into an array? Thanks for the help.
Jeff Oien

> I don't know of a way to do the insert in a single query (anyone?!?) with
> this... but
>
> assuming the fields in pic are
> id int PRI
> location varchar(30)
> picnumber int
> user varchar(20)
>
> $query = "Select max(picnumber) from pics where user=\"$user\"";
> $dbq = mysql_query($query,$dblink) or die("D'OH!");
>
> $picnum = mysql_result($dbq,0) + 1;
>
> $query = "Insert into pics values (\"\",\"$fileloc\",$picnum,\"$user\");
> $dbq = mysql_query($query,$dblink) or die("Great Googley Moogley!");
>
> Should get the new pic at the top (or bottom depending on how you look at
> it)
> of the order.
>
> Now if someone tells your program to delete the pic, I would call a function
> which
> would unlink the file then do
>
> //$id should be passed to function DeletePic()
> $query = "Select picnumber from pics where id = $id";
> $dbq = mysql_query($query,$dblink) or die("Looks like I picked the wrong day
> to quit smoking!");
>
> $number = mysql_result($dbq,0);
>
> $query = "Update pics set picnumber=picnumber-1 where user=\"$user\" and
> picnumber > $number";
> $dbq = mysql_query($query,$dblink) or die("Looks like I picked the wrong day
> to quit smoking!");
>
> $query = "Delete from pics where id=$id";
> $dbq = mysql_query($query,$dblink) or die("Looks like I picked the wrong day
> to start coding!");
>
> Get the idea?  Then if they wanted to rearrange the pics, you could just
> swap the picnumbers of the
> two pics they want to swap... or do something similar to the update line
> above.
>
> Sheridan Saint-Michel
> Website Administrator
> FoxJet, an ITW Company
> www.foxjet.com
>
>
> - Original Message -
> From: "Jeff Oien" <[EMAIL PROTECTED]>
> To: "PHP-DB" <[EMAIL PROTECTED]>
> Sent: Friday, August 31, 2001 1:38 PM
> Subject: RE: [PHP-DB] Previous | Next (Again)
>
>
> > Sorry but I'm just not getting this. I'm not sure how to get the order
> > of the pics in the first place or what do with the picnumber
> > column. If someone deletes a pic wouldn't the picnumbers higher than
> > it also need to be changed? I'm understanding everything else, even
> > the password stuff but this I'm just clueless.
> > Jeff Oien
> >
> > > I would add the field "picnumber int" or something to your DB.
> > > This is where the pic falls in the order of pics in the album.
> > >
> > > The the previous and next should be as simple as doing
> > > select picnumber,piclocation from album where user=$user and
> > > (picnumber=$number-1 or picnumber=$number+1);
> > >
> > > Then just check numrows.  If two make both prev and next links,
> > > if one make prev link if $return[0] < $number else make next link.
> > >
> > > If none, no links.
> > >
> > > This way, if the person wants to change the order of their pictures
> > > it is quite easy to write a function that allows them to swap the place
> > > of two pics.
> > >
> > > Make sense?
> > >
> > > Sheridan Saint-Michel
> > > Website Administrator
> > > FoxJet, an ITW Company
> > > www.foxjet.com
> > >
> > >
> > > - Original Message -
> > > From: "Jeff Oien" <[EMAIL PROTECTED]>
> > > To: "PHP-DB" <[EMAIL PROTECTED]>
> > > Sent: Thursday, August 30, 2001 8:18 PM
> > > Subject: [PHP-DB] Previous | Next (Again)
> > >
> > >
> > > > I'm having a hard time figu

[PHP-DB] Previous | Next (Again)

2001-08-31 Thread Sheridan Saint-Michel

 I don't know of a way to do the insert in a single query (anyone?!?) with
 this... but

 assuming the fields in pic are
 id int PRI
 location varchar(30)
 picnumber int
 user varchar(20)

 $query = "Select max(picnumber) from pics where user=\"$user\"";
 $dbq = mysql_query($query,$dblink) or die("D'OH!");

 $picnum = mysql_result($dbq,0) + 1;

 $query = "Insert into pics values (\"\",\"$fileloc\",$picnum,\"$user\");
 $dbq = mysql_query($query,$dblink) or die("Great Googley Moogley!");

 Should get the new pic at the top (or bottom depending on how you look at
 it)
 of the order.

 Now if someone tells your program to delete the pic, I would call a
function
 which
 would unlink the file then do

 //$id should be passed to function DeletePic()
 $query = "Select picnumber from pics where id = $id";
 $dbq = mysql_query($query,$dblink) or die("Looks like I picked the wrong
day
 to quit smoking!");

 $number = mysql_result($dbq,0);

 $query = "Update pics set picnumber=picnumber-1 where user=\"$user\" and
 picnumber > $number";
 $dbq = mysql_query($query,$dblink) or die("Looks like I picked the wrong
day
 to quit smoking!");

 $query = "Delete from pics where id=$id";
 $dbq = mysql_query($query,$dblink) or die("Looks like I picked the wrong
day
 to start coding!");

 Get the idea?  Then if they wanted to rearrange the pics, you could just
 swap the picnumbers of the
 two pics they want to swap... or do something similar to the update line
 above.

 Sheridan Saint-Michel
 Website Administrator
 FoxJet, an ITW Company
 www.foxjet.com


> ----- Original Message -
> From: "Jeff Oien" <[EMAIL PROTECTED]>
> To: "PHP-DB" <[EMAIL PROTECTED]>
> Sent: Friday, August 31, 2001 1:38 PM
> Subject: RE: [PHP-DB] Previous | Next (Again)
>
>
> > Sorry but I'm just not getting this. I'm not sure how to get the order
> > of the pics in the first place or what do with the picnumber
> > column. If someone deletes a pic wouldn't the picnumbers higher than
> > it also need to be changed? I'm understanding everything else, even
> > the password stuff but this I'm just clueless.
> > Jeff Oien
> >
> > > I would add the field "picnumber int" or something to your DB.
> > > This is where the pic falls in the order of pics in the album.
> > >
> > > The the previous and next should be as simple as doing
> > > select picnumber,piclocation from album where user=$user and
> > > (picnumber=$number-1 or picnumber=$number+1);
> > >
> > > Then just check numrows.  If two make both prev and next links,
> > > if one make prev link if $return[0] < $number else make next link.
> > >
> > > If none, no links.
> > >
> > > This way, if the person wants to change the order of their pictures
> > > it is quite easy to write a function that allows them to swap the
place
> > > of two pics.
> > >
> > > Make sense?
> > >
> > > Sheridan Saint-Michel
> > > Website Administrator
> > > FoxJet, an ITW Company
> > > www.foxjet.com
> > >
> > >
> > > - Original Message -
> > > From: "Jeff Oien" <[EMAIL PROTECTED]>
> > > To: "PHP-DB" <[EMAIL PROTECTED]>
> > > Sent: Thursday, August 30, 2001 8:18 PM
> > > Subject: [PHP-DB] Previous | Next (Again)
> > >
> > >
> > > > I'm having a hard time figuring this out. I have a photo album that
> > > displays
> > > > one image at a time. I want to have Previous and Next links for
images
> in
> > > > a users album. This was suggested:
> > > > http://www.phpbuilder.com/columns/rod2221.php3
> > > > but it seems to be more for a number of results instead of one.
> > > >
> > > > At first I used the id field which is auto_increment and did -1 for
> > > > previous +1 for next but then realized if they delete an image in
> > > > the album the id field is no longer successive by 1. I can count
> > > > the number of images in an album but not sure how to know which
> > > > is the first, which is the second etc. and know which the current
> > > > one is if the id field has gaps in it. Not sure if that made any
> sense.
> > > > Jeff Oien
> > > >
> > > > --
> > > > PHP Database Mailing List (http://www.php.net/)
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > To contact the list administrators, e-mail:
> [EMAIL PROTECTED]
> > >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] Previous | Next (Again)

2001-08-31 Thread Brunner, Daniel

Hello!!!

Now that I have found a better link to understand and use the code for
next/previous...here it is...

http://www.onlamp.com/pub/a/php/2000/11/02/next_previous.html

I use this idea with every database.

This also teaches you...mysql_fetch_object

PhPBuilder is "OK" but this one better to understandPlus it's a lot
cleaner

I think this is the best around...


Dan






> --
> From: Jeff Oien
> Reply To: [EMAIL PROTECTED]
> Sent: Thursday, August 30, 2001 8:18 PM
> To:   PHP-DB
> Subject:  [PHP-DB] Previous | Next (Again)
> 
> I'm having a hard time figuring this out. I have a photo album that
> displays
> one image at a time. I want to have Previous and Next links for images
> in
> a users album. This was suggested:
> http://www.phpbuilder.com/columns/rod2221.php3
> but it seems to be more for a number of results instead of one.
> 
> At first I used the id field which is auto_increment and did -1 for
> previous +1 for next but then realized if they delete an image in
> the album the id field is no longer successive by 1. I can count
> the number of images in an album but not sure how to know which
> is the first, which is the second etc. and know which the current
> one is if the id field has gaps in it. Not sure if that made any
> sense.
> Jeff Oien
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail:
> [EMAIL PROTECTED]
> 
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] Previous | Next (Again)

2001-08-31 Thread Jeff Oien

Sorry but I'm just not getting this. I'm not sure how to get the order
of the pics in the first place or what do with the picnumber
column. If someone deletes a pic wouldn't the picnumbers higher than
it also need to be changed? I'm understanding everything else, even
the password stuff but this I'm just clueless.
Jeff Oien

> I would add the field "picnumber int" or something to your DB.
> This is where the pic falls in the order of pics in the album.
> 
> The the previous and next should be as simple as doing
> select picnumber,piclocation from album where user=$user and
> (picnumber=$number-1 or picnumber=$number+1);
> 
> Then just check numrows.  If two make both prev and next links,
> if one make prev link if $return[0] < $number else make next link.
> 
> If none, no links.
> 
> This way, if the person wants to change the order of their pictures
> it is quite easy to write a function that allows them to swap the place
> of two pics.
> 
> Make sense?
> 
> Sheridan Saint-Michel
> Website Administrator
> FoxJet, an ITW Company
> www.foxjet.com
> 
> 
> - Original Message -
> From: "Jeff Oien" <[EMAIL PROTECTED]>
> To: "PHP-DB" <[EMAIL PROTECTED]>
> Sent: Thursday, August 30, 2001 8:18 PM
> Subject: [PHP-DB] Previous | Next (Again)
> 
> 
> > I'm having a hard time figuring this out. I have a photo album that
> displays
> > one image at a time. I want to have Previous and Next links for images in
> > a users album. This was suggested:
> > http://www.phpbuilder.com/columns/rod2221.php3
> > but it seems to be more for a number of results instead of one.
> >
> > At first I used the id field which is auto_increment and did -1 for
> > previous +1 for next but then realized if they delete an image in
> > the album the id field is no longer successive by 1. I can count
> > the number of images in an album but not sure how to know which
> > is the first, which is the second etc. and know which the current
> > one is if the id field has gaps in it. Not sure if that made any sense.
> > Jeff Oien
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Previous | Next (Again)

2001-08-30 Thread Jeff Oien

I'm having a hard time figuring this out. I have a photo album that displays
one image at a time. I want to have Previous and Next links for images in
a users album. This was suggested:
http://www.phpbuilder.com/columns/rod2221.php3
but it seems to be more for a number of results instead of one.

At first I used the id field which is auto_increment and did -1 for
previous +1 for next but then realized if they delete an image in
the album the id field is no longer successive by 1. I can count
the number of images in an album but not sure how to know which
is the first, which is the second etc. and know which the current
one is if the id field has gaps in it. Not sure if that made any sense.
Jeff Oien

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]