var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Query - General - Multiple counts within a single MySQL query
i am trying to do a multiple count in the same mysql query. i am trying to perform the count on two diffrent tables.
to get the total number of messages received by a member
to get the total number of favourite added by a member.
i have draft a a fucntion below.
the query is able to give an accurate report for the first select query but does not recognise the second one.
is there anything i am doing wrong, or is there a better way to go around this.
function workersmessages ( )
$select = " SELECT
COUNT( message)AS how_many
WHERE (receiver_id = '7')
WHERE ( sender_id = '7')
$query = $select ;
$result = @mysqli_query ($dbc, $query);
// $number = fetch_numberarray ($result );
look again, i'm sure you received two rows, not one
the query does indeed return results for the second SELECT
unfortunately it doesn't switch the column name half way through the results (this would be impossible anyway)
column names for the result set of a UNION query always come only from the first SELECT
Hello again R937
thank you for your response. you are indeed correct. i double checked the result, (within the MySQL database) and it did indeed produce both reports .
the question then is this; how do i call the second query;
below is my attempt to call it;
you will note that i was able to extract the first query but the system did not recongise the second one " no_fav " .
$general_search = workersmessages ( );
while ($row = mysqli_fetch_array ($general_search, MYSQLI_ASSOC))
//the first query.
$how_many =safe_output(trim( $row['how_many'])) ;
//the second query.
$no_fav =safe_output(trim( $row['no_fav '])) ;
sorry, i don't do php
but your second call is wrong -- there is no column called 'no_fav'
there is only one result set in a UNION query, and you need only one call
try it this way --
SELECT 'how many' AS which
, COUNT(*) AS total
WHERE receiver_id = 7
WHERE sender_id = 7