Login    Forum    Search    FAQ   Blog

Board index » Server Side Development » PHP




 Page 1 of 1 [ 3 posts ] 



Author Message
 Post subject: No ID result wid da left join :-(
 Post Posted: Thu Nov 12, 2009 11:12 am 
Offline

Joined: Sat Feb 21, 2009 2:27 pm
Posts: 59
I m havin 2 tables: news nd reactions. My motive is2 show all da
news items on a page wid da info how many reactions there r . At dis
moment it was workin when there was one r more reactions.however
when there are no reactions I wuld nt get da news_id 2 link 2 da newsitem.
Beneath my query:


Code:
function getAllNews($limit) {

$query = "
SELECT
n.news_id, n.head, n.date n.news n.text, COUNT(r.news_reactions_id) AS countReactions, r.name, r.reactionDate, r.message, r.news_id
FROM
news n
LEFT JOIN
news_reactions r
ON
r.news_id = n.news_id
GROUP BY
n.news_id
LIMIT
:limit
";

$stmt = $this->db->prepare($query);
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
$stmt->execute();
$array = $stmt->fetchAll();

return $array;
}


Top 
 Post subject: Re: No ID result wid da left join :-(
 Post Posted: Thu Nov 12, 2009 11:12 am 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
Code:
SELECT
n.news_id, n.head, n.date n.news n.text, r.countReactions , r.name, r.reactionDate, r.message, r.news_id
FROM
news n
LEFT JOIN
(SELECT name, reactionDate, message, news_id, COUNT(news_reactions_id) AS countReactions FROM news_reactions GROUP BY news_ID) AS r
ON
r.news_id = n.news_id
LIMIT
:limit


Top 
 Post subject: Re: No ID result wid da left join :-(
 Post Posted: Thu Nov 12, 2009 11:13 am 
Offline

Joined: Sat Feb 21, 2009 2:27 pm
Posts: 59
thanks for da response but it didnt cred my retardness!!
. It was n ot givin da result of da news_reactions table. Any idea how 2
solve?


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 3 posts ] 




Board index » Server Side Development » PHP


Who is online

Users browsing this forum: No registered users and 2 guests

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron