www.webdeveloper.com
Results 1 to 4 of 4

Thread: code for cycling through pictures one at a time

  1. #1
    Join Date
    Mar 2014
    Posts
    3

    code for cycling through pictures one at a time

    Hi, I am very new to php and mysql and have been struggling for a while with something that may be fairly simple.

    This is what I have created:
    A website where members can login and upload a profile picture.* Their profile picture is saved in a folder as member.jpg (where member is their username), and their username and password are saved in a mysql table. So when Adam creates a profile he will have a picture called adam.jpg and his username, adam, will be saved in the first column of the table.

    This is what I am now trying to create: A page that displays a single user's picture. After logging in, if I (I am another user) like the picture I click a like button. If not I click a dislike button. This causes the next user's picture to show up and I can like or dislike it, and I can thus cycle through all users who I have not previously liked/disliked. If I like a user then a database 'like' table will populate with my name in the first column and other users name in the second column. If I dislike a user my name will populate in the first column of a 'dislike' take and three other user's name in the second column.

    If someone could tell me basically how I can structure this using php I would really appreciate it. I am familiar with most php and mysql commands but I just don't know which ones I should use to create this efficiently. So if someone could point me to what commands, arrays, etc. I should use and in what order I would be really grateful.

    Thank you

  2. #2
    Join Date
    Feb 2014
    Location
    Canada
    Posts
    155
    Since you're assigning a username to each profile picture, you're ensuring they're unique. This allows for you to place all the pictures into 1 main folder rather than placing each picture into a separate folder. It also makes navigating to them a lot easier. You should have some code of restricting the pictures to a particular size and type, otherwise you're going to kill your server and bandwidth, especially if you hope to have a lot of users.

    In terms of getting the pictures when they're in 1 folder, I would use the glob function. For example:

    PHP Code:
    foreach(glob("pictures/*.jpg") as $photo) {
        
    # display each picture represented by $photo 

    Unfortunately, I'm a bit busy at work to handle the rest of your question, so I'll answer that later unless someone else does.

  3. #3
    Join Date
    Mar 2014
    Posts
    3
    Hello, this is a very useful start and I really appreciate it. Was wondering if you had time to add a bit more detail on next steps.

    Quote Originally Posted by Error404 View Post
    Since you're assigning a username to each profile picture, you're ensuring they're unique. This allows for you to place all the pictures into 1 main folder rather than placing each picture into a separate folder. It also makes navigating to them a lot easier. You should have some code of restricting the pictures to a particular size and type, otherwise you're going to kill your server and bandwidth, especially if you hope to have a lot of users.

    In terms of getting the pictures when they're in 1 folder, I would use the glob function. For example:

    PHP Code:
    foreach(glob("pictures/*.jpg") as $photo) {
        
    # display each picture represented by $photo 

    Unfortunately, I'm a bit busy at work to handle the rest of your question, so I'll answer that later unless someone else does.

  4. #4
    Join Date
    Feb 2014
    Location
    Canada
    Posts
    155
    For the next steps, you're going to have to cycle through your table where you store likes/dislikes for each user. The easiest way to create this would be to have each username along as a row and column. If you're not taking in user ratings for the pictures, then you can set the data types to Boolean and have it so the default is null (i.e. if nothing was entered, then it will say Null). Using this condition (and ensuring you cant rate yourself), you can use PDO's fetch to return each row as an array, then simply iterate through it. Depending how you want the website to behave, you can use AJAX and incorporate a jQuery or JavaScript slider to display the images, have them appear in a scrollable table (there's a lot of jQuery plug-ins for tables), etc... . While it is possible to store pictures in a database, I wouldn't do that, just so it's easier on the database. If you want to store additional information, such as the time at which someone uploaded the image (and display that), you could create another table and link via primary keys, however, an alternative is to get that data when the picture is initially uploaded and store it in a XML that's constantly being updated. The XML can be manipulated through a DOMDocument (allows immense control over it), SimpleXML (easier to use but doesn't allow for as much customization), etc... .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles