开发者

how should i get ONE row from mysql? ( fetch_array etc? )

I'm pretty sure i'm doing an extra loop here:

    $q = "SELECT * FROM genres WHERE genre.g_url = '$genre_url' LIMIT 1";   
    $res = mysql_query($q);
    while ($r = mysql_fetch_array($res, MYSQL_ASSOC)){
        foreach( array_keys($r) as $k ){
            $g[$k] = $r[$k];
        }
    }
    retu开发者_Python百科rn $g;


$q = "SELECT
          columns,
          you,
          want,
          to,
          read
      FROM
          genres
      WHERE
          genre.g_url = '".mysql_real_escape_string($genre_url)."'
      LIMIT 1";
$result = mysql_query($q) or die(mysql_error());
return mysql_fetch_assoc($result);

If there is no row in the database this will return false, otherwise the data of the row. And don't forget to escape user inputs...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜