0

I want to use multiple queries to count multiple values and display those values in a table.

$resultnieuws = mysql_query("select gamer_int, count(gamer_int) as gamer_count_nieuws     FROM berichten WHERE gamer_int LIKE 'Kenny' AND soort LIKE 'nieuws'");
$resultvideo = mysql_query("select gamer_int, count(gamer_int) as gamer_count_video FROM berichten WHERE gamer_int LIKE 'Kenny' AND soort LIKE 'video'");

echo $resultnieuws['gamer_count_nieuws'];
echo $resultvideo['gamer_count_video'];

The echo above gives me no result. What am i doing wrong?

0

1 Answer 1

1

Try like this-

    $resultnieuws = mysql_query("select gamer_int, count(gamer_int) as gamer_count_nieuws     FROM berichten WHERE gamer_int LIKE 'Kenny' AND soort LIKE 'nieuws'");
    $resultvideo = mysql_query("select gamer_int, count(gamer_int) as gamer_count_video FROM berichten WHERE gamer_int LIKE 'Kenny' AND soort LIKE 'video'");

    $row1 = mysql_fetch_array($resultnieuws);
    $row2 = mysql_fetch_array($resultvideo);

    echo $row1['gamer_count_nieuws'];
    echo $row2['gamer_count_video'];

Note: mysql_* functions are deprecated, using them not recommended.

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

2 Comments

Using them is even discouraged.
This won't work; my edit was declined for some reason, but you can't reference the field from $row1['gamer_count_nieuws'], you need to select it from the first row of the result. E.g. $row1[0]['gamer_count_nieuws']

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.