SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Maybe this one is simple too

    First ... thanks for the help on my first question. That had a simple solution and I hope this one does too.

    I'm trying to do a simple query that populates a variable

    its essentially

    $name = @mysql_query("SELECT name FROM author WHERE id='3'");
    echo "$name";

    I should get back the authors name -- joe smith ... instead I'm getting this: Resource id #2

    HUH? There isn't a single entry anywhere in my DB that would have a value anything like that. And baffling me even further is that when I go to my hosts mysql admin page and enter the same exact select statement I get the precise result I'm looking for.

    Thanks for any help ... I really almost thought I was kind of thinking I might get the hang of this.

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    700
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    The function mysql_query function returns a handle, not data. Use mysql_fetch_array to fetch records

    Code:
    $c = mysql_query("SELECT name FROM author WHERE id=3") or die("Error" . mysql_error() . " ");
    while ($r = mysql_fetch_array($c) )
    echo $c["name"] . "<br>";
    You should always check all database calls for errors.

  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Couple follow up questions:

    1. This is just so I'm clear -- I thought array was only used if you were pulling multiple bit s of data ... for instance if I wanted the whole list of names, not just one.

    2. In the above example why do you create $r before the fetch array? Is it a just in case you want to use this elsewhere or is there a reason within the limits of the example you posted?

    3. How come when I put the same select statement directly into the DB control panel I get an actual name as oppossed to the goofy value?

    I appreciate the help.
    Last edited by mayorquimby; Feb 9, 2005 at 09:08.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    those followup questions belong in the php forum (the first one did too)

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    Sorry about that ... right now they're sort of indistinguishable to me as they both fall under the category of "confusing things I never thought I'd be trying to teach myself."

    Any chance a mod could move this whole thing over to PHP so I don't have to start from 0 over there? thanks.


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
  •