Jump to content

Count how many fields in tables


invisionx

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

 

 

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.