Retieving data from mySQL with php

Discussion in 'PHP' started by Al Capone, Feb 6, 2006.

  1. #1
    I am trying to retrieve the games from a certain catigory in my arcade site so it displays 10 arcade games from each catigory.

    Below is my mySQL:


    And to make it easier for someone to help me, this is what I am currently using to get back the top 10 played games, what I want is for it to display 10 games from catigory "Movies" in the order of most played
    so here is the php code im using:


    I hope I wasnt confusing thank you in advance for reading this and help would be greatly appriciated.
     
    Al Capone, Feb 6, 2006 IP
  2. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #2
    I've been playing around the whole time since I posted, but still keep getting mySQL errors, I still at start ;(

    Any help is greatly appriciated
     
    Al Capone, Feb 6, 2006 IP
  3. averagejoe

    averagejoe Peon

    Messages:
    22
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    To make your code more portable and easier to manage you may want to check out PEAR and its DB-package.

    hxxp://pear.php.net/package/DB
     
    averagejoe, Feb 7, 2006 IP
  4. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #4
    First off, thanks for the response :)

    I colored red the important stuff for people in a rush because I wrote a bit.

    I don't want to make it complicated, the script I am using writes everything into a mySQL and I know all that needs to be change is something small.

    The script I want is so that it retrieves from catigory movies in order of times played, I don't think that you have to modify the current script that much (it already has ordering in order of times played) but maybe I'm wrong.

    Does anyone know what I should change in my code above (the second one) to make it so that it retrieves not only the top games played, but also
    - Games from catigory Movies
    - In order of most played (which is already done in second script)
    - Listing only top 10 (which is already done)

    I've been having a lot of trouble and I know most people here know what a pain it is to be stuck on the same thing for 2 days. Any help is greatfully appriciated.
     
    Al Capone, Feb 7, 2006 IP
  5. averagejoe

    averagejoe Peon

    Messages:
    22
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Do you connect to the database and select the correct database?

    mysql_connect("localhost", "user", "password");
    mysql_select_db("database");
     
    averagejoe, Feb 7, 2006 IP
  6. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #6
    First off, thanks again for your response.

    Yeah, I have no problem with code I currently use, it retrieves list of top 10 played games just fine and shows them, I just want to know what I should add to that code so that it shows the top 10 games played from the "Movie" catigory in the mySQL database.

    Sorry if I was confusing at first, any help is greatly appriciated, thanks.
     
    Al Capone, Feb 7, 2006 IP
  7. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #7
    Try something like this....






    <p><font size="1">
    <?
    $sql2 = "SELECT * FROM games where catagory LIKE movies ORDER BY played DESC LIMIT 0,10";
    $result2 = mysql_query($sql2);
    while($row2 = mysql_fetch_array($result2)) {
    ?>
    <a href="game.php?gameid=<? echo $row2["gameid"]; ?>">
    <? echo $row2["name"]; ?>
    </a><br>
    <?
    }
    ?>
    <?
    $sql2 = "SELECT * FROM games";
    $result2 = mysql_query($sql2);
    $totalplayed = 0;
    while($row2 = mysql_fetch_array($result2)) {
    $totalplayed = $totalplayed+$row2["played"];
    }
    ?></font></p></div>
     
    livingearth, Feb 7, 2006 IP
  8. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #8
    Thanks livingearth

    but it didnt work i got this error

    and that's after i changed catagory to category in the script you posted

    Any help is greatly appricited, if you see whats wrong please point it out, thanks in advance.
     
    Al Capone, Feb 7, 2006 IP
  9. Perrow

    Perrow Well-Known Member

    Messages:
    1,306
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    140
    #9
    And line 210 being?
     
    Perrow, Feb 7, 2006 IP
  10. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #10
    thanks for your reply

    I can't be sure because I am using php include, but could look that code over, I fixed the spelling of category and made movies Movies, but something is still wrong in that.

    any help is appriciated, thanks in advance.
     
    Al Capone, Feb 7, 2006 IP
  11. Al Capone

    Al Capone Well-Known Member

    Messages:
    784
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    140
    #11
    Al Capone, Feb 7, 2006 IP