Forum Moderators: coopster
$mresult = mysql_query("SELECT DISTINCT game FROM vids order by id desc limit 50", $link) or die ("query 1: " . mysql_error());
while ($mrow = mysql_fetch_array($mresult))
{
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM vids where game = '$mrow[game]'"), 0);
}
but for any $mrow[game] that has an ' in it a 0 is returned, how do I fix this?
while ($mrow = mysql_fetch_array($mresult)) { [b]$thisTitle=addslashes($mrow["title"]);[/b] $count = mysql_result(mysql_query("SELECT COUNT(*) FROM vids where game = [b]'$thisTitle'[/b]"), 0); } Note the use of quotes instead of apostrophes in the addslashes() function. This escapes the title's apostrophes (like
O\'Reilly)(but use with caution for other things ... see the manual page [us3.php.net]) and uses that escaped string as the $thisTitle variable's value. Then, when using that data in your SELECT statement, the escaped apostrophes do not interfere with the apostrophes you are using in your SELECT statement, and the value is passed as-is (no escaping) for comparison with the values in the database. In the future you may want to consider using addslashes() or another special-character-modifying function before you dump the data into the db.
I'm just trying to remember when I've ended up with unescaped quotes in my DB. Double escaped quotes through the magic of magic_quotes_gpc, yes, which ends up being being unescaped in the long run as the slash gets escaped.