SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: PHP MYSQL error

  1. #1
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP MYSQL error

    I am getting following error in my php page.
    PHP Code:
    $username="xxx";
    $password="xxx";
    $database="xxx";

    mysql_connect('xxxxxxxxxx',$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");
    $query mysql_query("SELECT * FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25");

    $result=mysql_query($query);
    $num=mysql_numrows($result) or die (mysql_error());

    mysql_close(); 

    Please help me to solve this error.

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rashidr View Post

    $query = mysql_query("SELECT * FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25");

    $result=mysql_query($query);
    [/PHP]
    .
    the error in these 2 lines is obvious.

    what were you trying to do there?

  3. #3
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah what he said ^^
    PHP Code:
    $query mysql_query("SELECT * FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25");

    $result=mysql_fetch_array($query);
    print_r($result); 

  4. #4
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to get last 25 results in db.

    Quote Originally Posted by Kalon View Post
    the error in these 2 lines is obvious.

    what were you trying to do there?

  5. #5
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I use mysql_fetch_array($query) I get this output with error






    Quote Originally Posted by JREAM View Post
    Yeah what he said ^^
    PHP Code:
    $query mysql_query("SELECT * FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25");

    $result=mysql_fetch_array($query);
    print_r($result); 

  6. #6
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  7. #7
    SitePoint Guru rashidr's Avatar
    Join Date
    Jun 2004
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got the solution.

    Change this line
    //$query = mysql_query("SELECT GameId, GameName, GameDesc FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25");


    to
    $query = "SELECT GameId, GameName, GameDesc FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25";
    $result=mysql_query($query);

  8. #8
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well done - glad you sorted it out in the end

  9. #9
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rashidr View Post
    Got the solution.

    Change this line
    //$query = mysql_query("SELECT GameId, GameName, GameDesc FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25");


    to
    $query = "SELECT GameId, GameName, GameDesc FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25";
    $result=mysql_query($query);
    Whats the difference between that two?.. i want to know just for my knowledge. I did not see any diff, both will give the same results, right?

    PHP Code:
    $num=mysql_numrows($result) or die (mysql_error()); 
    Isn't it be:
    PHP Code:
    $num=mysql_num_rows($result) or die (mysql_error()); 
    As mysql_numrows is deprecated.

  10. #10
    SitePoint Enthusiast LSC-Rob's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, NSW Australia
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mmarif4u View Post
    Whats the difference between that two?.. i want to know just for my knowledge. I did not see any diff, both will give the same results, right?
    The way the code was originally...

    Quote Originally Posted by rashidr View Post
    I am getting following error in my php page.
    PHP Code:
    $query mysql_query("SELECT * FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25");

    $result=mysql_query($query);
    $num=mysql_numrows($result) or die (mysql_error()); 
    $query was running the mysql_query, then $result was trying to run the mysql_query of a mysql_query... which of course will just confuse poor MySQL.

    And yes, mysql_numrows has been depreciated for some time.
    Rob G.
    ShopManager - Sales & Repair Business Management Software

  11. #11
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @LSC-Rob,
    Thanks for the info, but i know all that as i am following the thread.
    I was referring to the OP this line:
    PHP Code:
    //$query = mysql_query("SELECT GameId, GameName, GameDesc FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25"); 
    to this
    PHP Code:
    $query "SELECT GameId, GameName, GameDesc FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25";
    $result=mysql_query($query); 
    As if the OP run the 1st query without $result with mysql_query, it will be the same as $result taking out mysql_query from $query.
    I was just curious about that, because both are the same:
    PHP Code:
    $query mysql_query("SELECT GameId, GameName, GameDesc FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25"); 
    No $result above.
    same as:
    PHP Code:
    $query "SELECT GameId, GameName, GameDesc FROM rgames_flash WHERE GameAlive = '1' ORDER BY GameID DESC LIMIT 0, 25";
    $result=mysql_query($query); 
    Hope its clear as i was trying to focus on that point.

  12. #12
    SitePoint Enthusiast LSC-Rob's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, NSW Australia
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mmarif4u View Post
    @LSC-Rob,
    Thanks for the info, but i know all that as i am following the thread.
    Now I get ya... Sorry, it's been a long day!

    In that case, yes, AFAIK, the end result should be the same with either method... A bit of extra code with one, but a bit less readable with the other.
    Rob G.
    ShopManager - Sales & Repair Business Management Software


Bookmarks

Posting Permissions

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