Jump to content

Recommended Posts

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

<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>

<?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"); 
?>

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.