Jump to content

Simple count() issue


V

Recommended Posts

Well, I'm sure it's cake for you.  :P

 

I'm just trying to display the total number of posts under a category.  But for example instead of 4 I get 1111. My code is,

 

////////////////Category Query


			$category_table = mysql_query("SELECT * FROM categories", $connection);
			if (!$category_table) {
				die("Database query failed: " .mysql_error());
			}


			while ($row = mysql_fetch_array($category_table)) { 


			$cat_id=$row['car_id'];
			$cat_name=$row['cat_name'];


				echo "<a href=\"single_category.php?cat=" . urlencode($cat_id) . "\">
				$cat_name</a><br />";	


////////////////Total Posts Query					


			$total_posts = mysql_query("SELECT post_title FROM posts WHERE cat_id = {$row["cat_id"]}", $connection);
			if (!$total_posts) {
				die("Database query failed: " .mysql_error());
			}


			while ($row = mysql_fetch_array($total_posts)) { 

			$posts_nr = count($row['post_title']);	

			echo $posts_nr;	

			}//total_posts loop




			}//topics

 

BTW, I'm sorry for posting so many questions these past 2 days.. PHP is fun :)

Link to comment
https://forums.phpfreaks.com/topic/204994-simple-count-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.