I want to pass a php variable to mysql_query
such as:
$tty = '217';
$num_of_comments = mysql_query("SELECT count(*) FROM comments WHERE img_id = '.$tty.'");
$num_of_comments1 = mysql_fetch_array($num_of_comments);
$num_of_comments2 = $num_of_comments1[0];
echo $num_of_comments2 ;
However, I am not able to get the value needed in num_of_comments2
. It returns a 0 on echo.
Also I tried hardcoding 217 in the place of $tty
in the query. There it works.
I am also aware that this problem can be solved by mysqli/PDO
. Can someone be kind enough to help me with the code in that case?