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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Posts
    101
    Thanks
    17
    Thanked 5 Times in 5 Posts

    PHP MySQL column value for row

    Ok, so what I need to do is use MySQL in PHP to get a column value from a row. Currently I'm using the following code:
    Code:
    $query = mysql_query("SELECT blah FROM table WHERE blah = 'blah'");
    $result = mysql_fetch_array($query);
    $result = $result["blah"];
    And I have to do that because the query returns an array that is the same as what SELECT * FROM would return. Why wont it just return the column value I want? What do I have to do to make this happen?

    Ehhh.... Human error, it was returning the correct array. Sorry guys.

  • #2
    New Coder
    Join Date
    Feb 2010
    Location
    UK, North West
    Posts
    36
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Hello,
    I noticed that you don't show which type of array you're wanting returned.

    Also, if there's more than one matching result set use the following:
    PHP Code:
    $query mysql_query("SELECT blah FROM table WHERE blah = 'blah';");

    while(
    $result mysql_fetch_array($queryMYSQL_ASSOC))
    {
          print 
    $result["blah"] . "<br />\n";
    }
    mysql_free($result); # free the result :) 


  •  

    Posting Permissions

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