简体   繁体   中英

Mysql select only two items from table

I want to select only two items from table, not with * and row and etc...

I tried this, but its not working:

    $query = mysql_query("SELECT id, email FROM users WHERE nev = '$nev' LIMIT 1") or die (mysql_error());
    $id = mysql_result($query, 0);
    $email = mysql_result($query, 1); 

Any idea?

according to mysql_result documentation

the parameters can be described like this mysql_result ($result, $row , $field) You look for the 1st and 2nd row of an undefined field , which means 1st field of your select (id) when i suppose you look for the 1st row (and only since you have put LIMIt 1) of the 1st and 2nd field (id, email that you selected)

$id =mysql_result($query , 0 , 0 )
$email = mysql_result($query , 0, 1 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM