Hi, there
I have different queries fetching from different tables in one single page. i want to cut down the database tripping.
here is my code..
$query = "SELECT COUNT(*) as cnt_news FROM news";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$query = "SELECT COUNT(*) as cnt_adv FROM advertisements";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$query = "SELECT COUNT(*) as cnt_comm FROM comments";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$query = "SELECT SUM(CASE WHEN c.approve = '1' AND c.spam = '0' THEN 1 ELSE 0 END) AS cnt_approved,
SUM(CASE WHEN c.approve = '0' AND c.spam = '0' THEN 1 ELSE 0 END) AS cnt_unapproved,
SUM(CASE WHEN c.spam = '1' THEN 1 ELSE 0 END) AS cnt_spam
FROM COMMENTS c";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$query = "SELECT SUM(a.amount) as t_amnt,
SUM(a.cashpaid) as t_cpaid,
SUM(a.balance) as t_bal
FROM advertisements a";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
i am confused on how to make the query to select the values from three different tables, news, advertisement and comments. how do i cut my code and database trips?
thank you.