|
-
Apr 7th, 2006, 08:33 PM
#1
Thread Starter
Frenzied Member
[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.
-
Apr 8th, 2006, 12:30 AM
#2
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.'\''
));
-
Apr 8th, 2006, 01:15 AM
#3
Thread Starter
Frenzied Member
Re: Retrieve only one record.
Does it mean the $record variable is holding the empid value?
-
Apr 8th, 2006, 01:23 AM
#4
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.
-
Apr 8th, 2006, 01:34 AM
#5
Thread Starter
Frenzied Member
Re: Retrieve only one record.
Thank you pen. Now I have a basic knowledge in php.
-
Apr 8th, 2006, 05:54 AM
#6
<?="Moderator"?>
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|