invisionx Posted June 14, 2007 Share Posted June 14, 2007 I'm building a basic forum for my site and well im trying to make it count both the posts and the topics in each section but everytime i try different methods none of them will show any numbers and i know there are topics.. <?php $topics = mysql_query("SELECT forumid FROM forum_questions WHERE id = $id"); $topics = mysql_num_rows($topics); echo $topics; ?> that is a code i used but i also have a mysql query under it which gets the title and subtitle of the different forums.. <?php $sql = mysql_query("SELECT * FROM header ORDER BY `id`"); while($rows = mysql_fetch_array($sql)){ $datetime = date('D dS M Y, h:i a', strtotime($rows['datetime'])); ?> i hope someone can help me sort out my problem i dont even get an error either.. Thank you invisionx Link to comment https://forums.phpfreaks.com/topic/55528-count-how-many-fields-in-tables/ Share on other sites More sharing options...
christofurr Posted June 14, 2007 Share Posted June 14, 2007 I don't think you can define a variable twice. Post your entire code (include mysql connection). Link to comment https://forums.phpfreaks.com/topic/55528-count-how-many-fields-in-tables/#findComment-274377 Share on other sites More sharing options...
invisionx Posted June 14, 2007 Author Share Posted June 14, 2007 <table width="100%" height="20" border="0" align="center" cellpadding="2" cellspacing="0" bgcolor="#CFC095" class="Header_box"> <tr> <th width="80%" align="center" bgcolor="#514833" class="background_head"><strong>Forum</strong></th> <th width="10%" align="center" bgcolor="#514833" class="background_head"><strong>Topic</strong></th> <th width="10%" align="center" bgcolor="#514833" class="background_head"><strong>Posts</strong></th> </tr> </table> <table width="100%" border="1" bordercolor="CFC095" align="center" cellpadding="0" cellspacing="0" bgcolor="#CFC095" class="Box_border"> <?php $id = $_GET['id']; $sql = mysql_query("SELECT * FROM header ORDER BY `id`"); while($rows = mysql_fetch_array($sql)){ $datetime = date('D dS M Y, h:i a', strtotime($rows['datetime'])); ?> <tr> <td width="80%" bgcolor="#4D4531" class="background"><a href="../index.php?pages=topic&id=<?php echo $rows['id']; ?>"><?php echo $rows['heading']; ?></a><BR><?php echo $rows['description']; ?></td> <td width="10%" align="center" bgcolor="#4D4531" class="background"><!--how many topics will go here--></td> <td width="10%" align="center" bgcolor="#4D4531" class="background"><!--how many posts will go here--></td> </tr> <?php if($_SESSION['user_level'] == 5) { ?> <tr> <td width="100%" align="center" bgcolor="#4D4531" class="background" colspan="5"><a class="two" href="../index.php?pages=topic_edit&id=<?php echo $rows['id']; ?>">Edit</a> | <a class="two" href="../index.php?pages=forum_functions&action=delete&id=<?php echo $rows['id']; ?>">Delete</a></td> </tr> <?php } } ?> <?php if(isset($_SESSION['user_name'])){ ?> <tr> <td colspan="5" align="right" bgcolor="#4D4531" class="background"><a href="../index.php?pages=add_heading"><strong>Create New Topic</strong> </a></td> </tr> <?php } ?> </table> Link to comment https://forums.phpfreaks.com/topic/55528-count-how-many-fields-in-tables/#findComment-274378 Share on other sites More sharing options...
christofurr Posted June 14, 2007 Share Posted June 14, 2007 Where do you connect to your database? Link to comment https://forums.phpfreaks.com/topic/55528-count-how-many-fields-in-tables/#findComment-274379 Share on other sites More sharing options...
invisionx Posted June 14, 2007 Author Share Posted June 14, 2007 thats in index.php page Link to comment https://forums.phpfreaks.com/topic/55528-count-how-many-fields-in-tables/#findComment-274385 Share on other sites More sharing options...
christofurr Posted June 14, 2007 Share Posted June 14, 2007 Well, I'm a bit confused, but that's probably because I just started studying PHP two weeks ago. I guess it would depend on how you have your database tables arranged. Do you have one table for topics and one table for posts? Link to comment https://forums.phpfreaks.com/topic/55528-count-how-many-fields-in-tables/#findComment-274411 Share on other sites More sharing options...
MemphiS Posted June 14, 2007 Share Posted June 14, 2007 <?php $topics = mysql_query("SELECT forumid FROM forum_questions WHERE id = $id"); $topics = mysql_num_rows($topics); echo $topics; ?> You cant have two variables named the same. This will work below. <?php $topics = mysql_query("SELECT `forumid` FROM `forum_questions` WHERE `id` = '$id'"); $top_count = mysql_num_rows($topics); echo("$top_count"); ?> Link to comment https://forums.phpfreaks.com/topic/55528-count-how-many-fields-in-tables/#findComment-274414 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.