Guys good day. How can I retrieve one record?
I want to get the empid value. How can I do that? I only know how to fetch a recordset not a single record.PHP Code:$query="select empid from dtrlog where name='$name' and password='$pass'";
Printable View
Guys good day. How can I retrieve one record?
I want to get the empid value. How can I do that? I only know how to fetch a recordset not a single record.PHP Code:$query="select empid from dtrlog where name='$name' and password='$pass'";
A slight kludge, but
PHP Code:$record = mysql_fetch_assoc(mysql_query(
'select distinct `empid` from `dtrlog` '.
'where `name` = \''.$name.'\' and `password` = \''.$pass.'\''
));
Does it mean the $record variable is holding the empid value?
Nah, $record will hold the row, you need to do $record['empid'] to get the field value.
Or alternatively you could do this
which does it in one go.PHP Code:$empid = mysql_result(mysql_query(
'select distinct `empid` from `dtrlog` '.
'where `name` = \''.$name.'\' and `password` = \''.$pass.'\''
), 0);
Thank you pen. Now I have a basic knowledge in php. :)
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.