Personally I would start from scratch and get each part working at a time. For a start you have $query_count2 and $votes twice and the code seems all jumbled up.
I guess you are trying to convert some code into an integer
This is probably your problem $vcount=mysqli_query($db_conx,$sql); as this is code and not a result
Isn’t his problem actually with the line of code below that?
$popularity=($votes/$vcount)*100;
He is using the $vcount variable (which will either contain FALSE or a mysqli_result object if the query was successful) in an integer context (as the divisor).
@shail_arya, your two queries could be amalgamated and your code could be simplified in general:
$sql = "SELECT COUNT(id), COUNT(view_count) FROM blog WHERE username = '{$u}' AND deleted = 0";
$query = mysqli_query($db_conx, $sql);
list($votes, $vcount) = mysqli_fetch_row($query);
if(($popularity = ($votes / $vcount) * 100) < 0)
$popularity = 0;
This code seems to be perfect… But when i realizes now that i dont need the count of column. I need the individual sum of these columns. I googled and found that can be done using SUM but how to use to display is not clear… Can you help me on that too.
One more thing above you have used’ {$u '}, is it for some purpose or i can use normal '$u '.
Can you explain to me a little more about what you’re trying to achieve? Seeing your database structure and what data you’re trying to return from it would be a great help.
As for using the braces around the variable, it’s just my preferred method of interpolation (where variables are included into a string to be parsed). I find it a clearer syntax because the braces clearly delineate the variable from the surrounding string.
Now a user can have more than one topics.
So i want to SUM all the likes of a user of his all topics to a variable X and SUM of all the view to variable Z