Simple way to read single record from MySQL

后端 未结 20 1370
一整个雨季
一整个雨季 2020-11-30 23:46

What\'s the best way with PHP to read a single record from a MySQL database? E.g.:

SELECT id FROM games

I was trying to find an answer in t

20条回答
  •  囚心锁ツ
    2020-12-01 00:41

    I agree that mysql_result is the easy way to retrieve contents of one cell from a MySQL result set. Tiny code:

    $r = mysql_query('SELECT id FROM table') or die(mysql_error());
    if (mysql_num_rows($r) > 0) {
        echo mysql_result($r); // will output first ID
        echo mysql_result($r, 1); // will ouput second ID
    }
    

提交回复
热议问题