Results 1 to 6 of 6

Thread: [RESOLVED] Retrieve only one record.

  1. #1

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Resolved [RESOLVED] Retrieve only one record.

    Guys good day. How can I retrieve one record?
    PHP Code:
    $query="select empid from dtrlog where name='$name' and password='$pass'"
    I want to get the empid value. How can I do that? I only know how to fetch a recordset not a single record.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Retrieve only one record.

    A slight kludge, but

    PHP Code:
    $record mysql_fetch_assoc(mysql_query(
      
    'select distinct `empid` from `dtrlog` '.
      
    'where `name` = \''.$name.'\' and `password` = \''.$pass.'\''
    )); 

  3. #3

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Retrieve only one record.

    Does it mean the $record variable is holding the empid value?

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Retrieve only one record.

    Nah, $record will hold the row, you need to do $record['empid'] to get the field value.

    Or alternatively you could do this
    PHP Code:
     $empid mysql_result(mysql_query(
      
    'select distinct `empid` from `dtrlog` '.
      
    'where `name` = \''.$name.'\' and `password` = \''.$pass.'\''
    ), 0); 
    which does it in one go.

  5. #5

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Retrieve only one record.

    Thank you pen. Now I have a basic knowledge in php.

  6. #6
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: [RESOLVED] Retrieve only one record.

    Just for further reference you can use the LIMIT
    keyword to limit the amount of records that you want returned, athough in this case it isn't advised.

Posting Permissions

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



Click Here to Expand Forum to Full Width