Home N-13 News Forums Help Search
RegisterForgot password?
How to add image to post necklacesdiscou
Known bugs - 4.0.3 necklacesdiscou

Latest N-13 News 4.0.3

What is N-13 News?
Where can I get help?
Known bugs

Forums Tutorials [NEWS ADDON] Display how many posts are in a selected category
Vyb3
Posted on 21 Aug 2008, 18:12:34

Access: Member
Total Posts: 9
Joined: 2008-08-16

I came up with this code for my website, I thought I would post it should anybody find it useful, its a short simple snippet really;

Code:
<?php 

define
('SQL_HOST','localhost'); // Connect to your mySQL database
define('SQL_USER','xxx');
define('SQL_PASS','xxx');
define('SQL_DB','xxx');

$link = mysql_connect(SQL_HOST,SQL_USER,SQL_PASS)
or die(
'Could not connect to the mysql server...; ' . mysql_error());

mysql_select_db(SQL_DB,$link)
or die(
'Could not select database...; ' . mysql_error());

$query = mysql_query("SELECT COUNT(*) AS totalposts FROM news30_story WHERE catid='6'"); //Change the catid here to the id of your category that you want to count the posts for. To find out the id for your category go to the news admin panel, go to the categories page proceed to scroll over your category then look in the status bar of your browser, the last number is your category id 
 
$query = mysql_fetch_array($query);

$number = $query['totalposts'];

echo 
$number;

?>
#352
Chris
Posted on 22 Aug 2008, 02:47:43

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

This looks good, one thing I'd change though is the query your using, I've edited it slightly so the user doesn't have to enter the id of the category, instead they can just enter the category name.

Code:
<?php
$catname 
= 'Cat2';
$query = mysql_query("SELECT COUNT(*) FROM $newstable INNER JOIN $newscats ON $newstable.catid = $newscats.id WHERE $newscats.name = '$catname'");
?>
#361
Last edited by Chris at 2008-08-22 09:37:50 Reason:
Hackerzlab
Posted on 25 Sep 2009, 11:12:19

Access: Member
Total Posts: 31
Joined: 2009-09-25

and how do i set the number of news article for that specific category?

m new to php.
#885
Mattycat
Posted on 22 Oct 2009, 13:05:46

Access: Member
Total Posts: 42
Joined: 2008-06-25

I looks like it shows you the number of news items which are in that category.
#1100
Network-13.com © 2013