PHP MySQL select not returning information

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rando1000
    New Member
    • Aug 2007
    • 80

    PHP MySQL select not returning information

    I'm relatively new at PHP, and am trying to pull data from a mysql database. It should be noted before I ask this that I've got an Insert query working, so I know I'm logged into the database properly.

    What I'm trying to do is pull an ID from the database and display it on screen. Eventually I'll be incrementing the ID and including it in my Insert statement, but for now I just want to know I'm getting the right number.

    Code:
    $query="Select Max(OrderID) from database.orders";
    $q=mysql_query($query) or die ('Error reading database' .  mysql_error());
    $qRow = mysql_fetch_array($q);
    $qvar = $qRow["OrderID"];
    echo "$qvar";
    The code executes clean through, but the echo statement does not return anything. I've run the query in mysql workbench and it returns the value of 4. Anything jump out as incorrect?
    Last edited by Dormilich; Sep 18 '10, 06:46 PM. Reason: fixed [code] [/code] tags
  • rando1000
    New Member
    • Aug 2007
    • 80

    #2
    Nevermind, solved it myself. The query should be "Select Max(OrderID) As OrderID..."

    Thanks anyway.

    Comment

    • cutesrivastavaabhi
      New Member
      • May 2010
      • 8

      #3
      u just remove ur semicolan before the code and put it to end of the this line

      Comment

      Working...