0

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;

1 Answer 1

3
$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...

Sign up to request clarification or add additional context in comments.

1 Comment

Except that or die(...) is almost certainly the wrong thing to do (phpfreaks.com/blog/or-die-must-die), and outputting the result of mysql_error discloses too much information (msdn.microsoft.com/en-us/library/…).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.