다른 테이블의 응답 수에 관한 포럼 주제를 가져 오는이 쿼리에 문제가 있습니다. 내가 전에 왼쪽으로 조인을 시도했지만 일부 데이터는 내 while 루프에서 제외되었습니다. 그것은 오류로 나를이 있습니다Where Join Where Where Where Where 절
SELECT forum_topics.*, COUNT(forum_posts.comment_id) AS replies
FROM forum_topics
WHERE forum_topics.subcat_id = '$subcatid'
LEFT JOIN forum_posts
ON forum_topics.topic_id=forum_posts.topic_num
ORDER BY replies DESC
는 : 내가 사용하는 에코
SELECT * FROM forum_topics WHERE subcat_id = '$subcatid' ORDER BY date DESC
:
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'LEFT JOIN forum_posts ON
forum_topics.topic_id=forum_posts.topic_num ORDER BY r' at line 1
이 전에 일하던 쿼리입니다
$getChildCategory = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($get);
if($num == 0){ echo 'No Posts';}
else{
while ($row = mysql_fetch_assoc($get)){
반향을 할 때 왼쪽 조이와 함께 1 개의 결과 만 얻습니다. n 그러나 오래된 것와 더불어 나는 2를 가지고 있었다. 그것은 내가 기대했던 것이다.
새 응용 프로그램에서 mysql_query를 사용하면 안됩니다. 너무 위험합니다. 대신 PDO 또는 mysqli를 사용하십시오. [적절한 SQL 이스케이프] (http://bobby-tables.com/php)를 사용하십시오. – tadman