Merdok Posted September 19, 2010 Share Posted September 19, 2010 Hi Guys, I've been using PHP for a few years now but for some reason I can never seem to get my head around arrays, basically I have a blog site that I want to show all posts that have been posted in public categories but ignore those in the private categories, I had the idea to put all the private category ID's into an array and use that to check against the posts, however my array isn't working out the way I'd hoped. This is what I have: $isPrivate = mysql_query("SELECT categoryID FROM mod_cat WHERE isPrivate =1") or die (mysql_error()); while ($isPrivateList = mysql_fetch_array($isPrivate, MYSQL_NUM)) { $ignoreList = $isPrivateList; } However this isn't working at all. I know its wrong I just can't work out how to make it right. This is the mySQL I want to use it with: mysql_query("SELECT COUNT(*) AS total_entries FROM mod_posts WHERE articlePosted =1 AND articleCat != $ignorelist") Could anyone please help me? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/213811-excluding-a-category-from-a-list/ Share on other sites More sharing options...
sasa Posted September 19, 2010 Share Posted September 19, 2010 SELECT COUNT(p.*) AS total_entries FROM mod_posts AS p LEFT JOIN mod_cat AS c ON c.categoryID = p.articleCat WHERE p.articlePosted =1 AND c.isPrivate != 1 Quote Link to comment https://forums.phpfreaks.com/topic/213811-excluding-a-category-from-a-list/#findComment-1112828 Share on other sites More sharing options...
Merdok Posted September 19, 2010 Author Share Posted September 19, 2010 LOL thanks.... I'm rubbish at joins as well... I'll give that a try later. Quote Link to comment https://forums.phpfreaks.com/topic/213811-excluding-a-category-from-a-list/#findComment-1112832 Share on other sites More sharing options...
Merdok Posted September 20, 2010 Author Share Posted September 20, 2010 hmm... that didn't work, I'm getting this error: 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 '*) AS total_entries FROM mod_posts AS p LEFT JOIN mod_cat AS c ' at line 1 This is how I used it: $blogCounter = mysql_query("SELECT COUNT(p.*) AS total_entries FROM mod_posts AS LEFT JOIN mod_cat AS c ON c.categoryID = p.articleCat WHERE p.articlePosted =1 AND c.isPrivate != 1") or die(mysql_error()); $row = mysql_fetch_row($blogCounter); $total_entries = $row[0]; Quote Link to comment https://forums.phpfreaks.com/topic/213811-excluding-a-category-from-a-list/#findComment-1113346 Share on other sites More sharing options...
the182guy Posted September 20, 2010 Share Posted September 20, 2010 Syntax error here FROM mod_posts AS LEFT JOIN Change to FROM mod_posts AS p LEFT JOIN Quote Link to comment https://forums.phpfreaks.com/topic/213811-excluding-a-category-from-a-list/#findComment-1113351 Share on other sites More sharing options...
Merdok Posted September 20, 2010 Author Share Posted September 20, 2010 Still getting the same error. Could it be that the p.* has been referenced before it has been created? Thanks by the way, that would no doubt have caused further headaches later Quote Link to comment https://forums.phpfreaks.com/topic/213811-excluding-a-category-from-a-list/#findComment-1113354 Share on other sites More sharing options...
the182guy Posted September 20, 2010 Share Posted September 20, 2010 Try changing it to the Primary Key of your mod_posts table, example SELECT COUNT(p.id) AS total_entries Quote Link to comment https://forums.phpfreaks.com/topic/213811-excluding-a-category-from-a-list/#findComment-1113362 Share on other sites More sharing options...
Merdok Posted September 20, 2010 Author Share Posted September 20, 2010 That's a bingo Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/213811-excluding-a-category-from-a-list/#findComment-1113365 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.