www.webdeveloper.com
Results 1 to 4 of 4

Thread: $result = mysql_query... What is '$result'? An array?

  1. #1
    Join Date
    Aug 2006
    Posts
    255

    $result = mysql_query... What is '$result'? An array?

    Assume the following code:
    PHP Code:
    <?php
    $username
    ="david";
    $password="passwd123";
    $database="dbase1";

    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");

    $query "SELECT * FROM contacts";
    $result=mysql_query($query);


    mysql_close();


    ?>
    What type of variable is $result? I assumed it was a multi-dimensional array, but why can't I echo one of its values to the browser by using:

    echo $result[first][0];

    (There is a field in the table called 'first').

    Does the function mysql_query() create some sort of special data type that can only be used by other, pre-defined functions?

    Thanks.
    Last edited by callumd; 08-23-2006 at 10:53 PM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    Quote Originally Posted by callumd
    ...
    Does the function mysql_query() create some sort of special data type that can only be used other, pre-defined functions?

    Thanks.
    Yes, it returns a "resource ID" which can then be used by any of the mysql_fetch_*() functions, and other functions such as mysql_data_seek() and mysql_num_rows().
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2006
    Posts
    255
    Thanks NogDog,

    Lightning quick answer, much appreciated.

    Callum.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    No problem. See http://www.php.net/manual/en/functio...etch-assoc.php for a typical example of using a mysql_query() result.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles