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 13 of 13
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Highlighting latest added records ?

    Hi there,

    I am building a simple "movie database" script for personal use in php. It's just some practise to get a bit better at it.

    Now, My movies are alphabeticly listed, but I would like to highlight the last 3 added films.
    I guess this should be possible ? I have id & title for each film in my mysql table.

    Thanks alot for reading

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You could probably add another column that holds the unix timestamp for when the movie was added then use a query like this
    Code:
    $query = "SELECT * FROM tablename ORDER BY timeadded DESC LIMIT 3";
    That should give you the lastest 3 entries. You can probably do something like this as well
    Code:
    $query = "SELECT * FROM tablename ORDER BY id DESC LIMIT 3";
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts
    Your all movies are in one section or are there any different categories

    Probably there will be different categories of movies and do you want to show last three in every section or as a whole

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    If you have a time added feild, then you can do something like this:

    Code:
    SELECT * FROM movies ORDER BY movie_name ASC
    And run this as well, to get the IDs for the latest 3.

    Code:
    SELECT movie_id FROM movies ORDER BY time_added DESC LIMIT 3
    Then when you loop through the movies, just check to see if the movie you are displaying is within the results of the last query above.
    If I'm postin here, I NEED YOUR HELP!!

  • #5
    New Coder
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Ultragames View Post
    Then when you loop through the movies, just check to see if the movie you are displaying is within the results of the last query above.
    The previous steps work perfectly, only I don't know how to do the check. Can anyone enlighten me on this?

    Thanks !

  • #6
    Regular Coder
    Join Date
    Aug 2002
    Location
    Oregon, United States of America
    Posts
    882
    Thanks
    1
    Thanked 9 Times in 9 Posts
    it depends on how you are looping through the first query. The easiest way to do it is to create an array out of the second query, and then run an in_array() on the loop for the first query.
    If I'm postin here, I NEED YOUR HELP!!

  • #7
    New Coder
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Ultragames View Post
    it depends on how you are looping through the first query. The easiest way to do it is to create an array out of the second query, and then run an in_array() on the loop for the first query.
    PHP Code:
    <?php
    case view:
            if (
    $_POST['genre']=="alles") {
            
    $query "SELECT *
                      FROM divx INNER JOIN genres ON genreid=genres.id"
    ;
            
            }
            else {
          
    $query "SELECT *
                      FROM divx INNER JOIN genres ON genreid=genres.id
                      WHERE genreid = \"{$_POST['genre']}\""

            }          
    ?>
            <table class="result">
                <tr>
                    <td class="top">Titel</td>
                    <td class="top">Genre</td>
                </tr>
            <?php
            
    if ($result=$link->query($query)) {
              for (
    $i=0$i $result->num_rows$i++) {
                
    $rij$result->fetch_assoc();
                print(
    "<tr>\n");
                print(
    "<td class=\"cell1\"><a href=\"http://www.imdb.com/find?s=tt&q={$rij['titel']}\" class=\"titel\">{$rij['titel']}</a></td>\n");
                print(
    "<td class=\"cell2\">{$rij['genre']}</td>\n");
                print(
    "</tr>\n");
            
              }
              
    $result->close();
            } 
            
    $link->close() or die("Kan link met $dbserver niet sluiten.");
            
    ?>
            </table>
            <a href="film.php">Terug</a>
    <?php
    break;
    This is the code I m using right now. The if check is for sorting by genre. Than I put the results in the $rij array.

  • #8
    New Coder
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Bump

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by maikelv View Post
    The previous steps work perfectly, only I don't know how to do the check. Can anyone enlighten me on this?

    Thanks !
    You don't know how to do which check?
    Have you added a time field?

  • #10
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    If your 'id' field is autoincrement then just use the following query:

    PHP Code:
    SELECT FROM table ORDER BY id DESC LIMIT 3 

  • #11
    New Coder
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    You don't know how to do which check?
    Have you added a time field?
    The check to see if my results are in t the query for the first 3 results.
    (in order to highlight them).

  • #12
    New Coder
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Anyone ?

  • #13
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You haven't answered our questions yet. Have you even tried what we've given you?
    Quote Originally Posted by Inigoesdr
    Have you added a time field?
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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