Hi everyone.
i am a little confused about this issue. i draft a query in which i used numrous select statements, within the same query; i then join each of the select statements together with a UNION ALL.
I tested the query in the MySQL and it works. the only problem is that i dont know how to extract this information in my loop i.e
while ($row = mysqli_fetch_array ($general_search, MYSQLI_ASSOC))
it might be easier at this point if i show you what i am referring to;
function workersmessages ( )
{
global $dbc;
select = " SELECT
COUNT( message)AS how_many
FROM massages
WHERE (receiver_id = '7')
union all
SELECT
COUNT( message)AS how_many_sent
FROM massages
WHERE ( sender_id = '7')
union all
SELECT
COUNT( message)AS how_many_unread
FROM massages
WHERE (receiver_id = '7')
AND (is_read = 'U')
";
$query = $select ;
$result = @mysqli_query ($dbc, $query);
return $result;
}
the above is my MySQL function to retrive the data; below is PHP fuction to retrive the data from the function;
$general_search = workersmessages ( );
while ($row = mysqli_fetch_array ($general_search, MYSQLI_ASSOC))
{
$how_many =safe_output(trim( $row['how_many'])) ;
}
you will note that the mysql query doesn’t switch the column name half way through the query;accordingly the data in the SELECT statements ( after the inital one) do not have names . i therefore dont know how to call them in my loop.
i would really appriciate any advice/reccomendations.
warm regards
Andreea 115