tags:

views:

54

answers:

1

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];
        }
    }
    return $g;
+3  A: 
$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...

Progman
Except that `or die(...)` is almost certainly the wrong thing to do (http://www.phpfreaks.com/blog/or-die-must-die), and outputting the result of `mysql_error` discloses too much information (http://msdn.microsoft.com/en-us/library/ms995351.aspx#securityerrormessages_topic2).
outis