SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    katonah
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select query not working!

    why isn't this working?

    I have a database connection established yadda yadda...
    but when i try to grab the name of a user like this

    PHP Code:
    <?php
      $user 
    = @mysql_query('SELECT user_firstname FROM people WHERE id=1');
      if (!
    $user) {
        exit(
    '<p>Problem with Query: ' .
            
    mysql_error() . '</p>');
      } 
      
    ?>
    and echo it like so

    Hey
    PHP Code:
    Hey <?php echo $user ?>
    i end up with this

    Hey Resource id #4

    What I want to end up with is Hey Casey

    my database looks like this

    table --> people

    id ------------------ 1
    user_firstname --- Casey

  2. #2
    SitePoint Guru gavwvin's Avatar
    Join Date
    Nov 2004
    Location
    Cornwall, UK
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_query returns a resource, that is a link to the real results. To do all mysql select queries you would use something like:
    PHP Code:
    $query="SELECT * FROM stuff";
    $results=mysql_query($query);
    while(
    $row=mysql_fetch_assoc($results)) {
        
    //$row contains an array of that row of the results.
        //so to get the value of the coulmn id you would do $row['id'] and to get user_firstname you'd echo $row['user_firstname'];

    I recommend you look the php manual on mysql functions: php.net/mysql


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
  •