How to add "category=travel" to this code? ..help

Discussion in 'PHP' started by Andy_ameed, Jun 15, 2010.

  1. #1
    Hi, I am having problems with adding category to this code below

    $Threadquery = mysql_query("SELECT threadid, count(threadid) as count FROM comments GROUP BY threadid ORDER BY count DESC LIMIT $count , 1 ") or die(mysql_error());
    PHP:

    Thanks
     
    Andy_ameed, Jun 15, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    If I have understood you correctly, try this:

    
    $Threadquery = mysql_query("SELECT threadid, count(threadid) as count FROM comments WHERE category='travel' GROUP BY threadid ORDER BY count DESC LIMIT $count , 1 ") or die(mysql_error());
    
    Code (markup):
     
    s_ruben, Jun 16, 2010 IP
  3. Andy_ameed

    Andy_ameed Active Member

    Messages:
    129
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Thanks s_ruben

    It is showing the error below...

    Unknown column 'category' in 'where clause'
     
    Andy_ameed, Jun 16, 2010 IP
  4. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #4
    you should join two tables here, i guess it's comments vs post, post might have category there..
     
    gapz101, Jun 16, 2010 IP
  5. Andy_ameed

    Andy_ameed Active Member

    Messages:
    129
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    <table width="378" border="0">
    		            <tbody> 
    					<?php
    		  			 	$Threadquery = mysql_query("SELECT  threadid, count(threadid) as count FROM comments GROUP BY threadid ORDER BY count DESC LIMIT $count , 1 ") or die(mysql_error()); 
    					  	$Threaddata = mysql_fetch_array($Threadquery);						
    						  $NoThreadquery = mysql_query("SELECT * FROM threads where threadid='".$Threaddata['threadid']."'") or die(mysql_error());  	
    		  					$NoThreadComments = mysql_fetch_array($NoThreadquery);  
    					 ?>
                        <tr valign="top">
    		              <td width="15" align="center" valign="top"><span style="font-family: 'Palatino Linotype'; font-size: 14px; color: rgb(255, 255, 255);">+</span></td>
    		              <td width="353"><span style="font-family: 'Palatino Linotype'; font-size: 12px;"><a href="postdetails.php?thread=<?=$NoThreadComments['threadid'];?>&type=<?=$NoThreadComments['categoryid'];?>" rel="nofolloow" style="text-decoration: none; color: rgb(51, 102, 153);"><?=$NoThreadComments['title'];?></a><span style="color: rgb(143, 71, 143);"><br>
    		                by <?=$NoThreadComments['username'];?></span> <span style="color: rgb(237, 243, 254);"><?=$Threaddata['count'];?> comment(s)</span></span></td>
    		              </tr>
                         
    		            </tbody></table>
    PHP:
    here is the full code.. right now the code shows threads from all categories, My aim is to show threads from category (travel)

    Thanks
     
    Andy_ameed, Jun 16, 2010 IP
  6. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #6
    Can you show the tables structures of the database? I mean the structure of the table comment and the structure of the table in which is the column category.
     
    s_ruben, Jun 16, 2010 IP