SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    counting replies

    hi there

    i have functions below that used to count replies on specific thread/message

    Code:
    //funtion for pagination
    function adminpagination()
    {
    $display = 10;
    	
    	
    	if (isset($_GET['np'])) 
    	{ 
    		$num_pages = $_GET['np'];
    	} 
    	else 
    	{ 
    		$query = "SELECT * FROM posts"; 
    		$query_result = mysql_query ($query);
    		$num_records = @mysql_num_rows ($query_result);
    		
    		if ($num_records > $display) 
    		{ 
    			$num_pages = ceil ($num_records/$display);
    		} 
    		else 
    		{
    			$num_pages = 1;
    		}
    	}
    	
    	
    	if (isset($_GET['s'])) 
    	{ 
    		$start = $_GET['s'];
    	} 
    	else 
    	{
    		$start = 0;
    	}
    			
    	// Make the query.
    	$query = "SELECT DATE_FORMAT(postupdate, '%M %D, %Y - %l:%i %p'), title, postID, firstname FROM posts AS p, users AS u
    			WHERE p.userID = u.userID ORDER BY postupdate DESC LIMIT $start, $display";		
    	$result = @mysql_query ($query); 
    	$num = mysql_num_rows ($result); 
    	
    	if ($num > 0) 
    	{ 	
    		if ($num_pages > 1) 
    		{			
    			
    			$current_page = ($start/$display) + 1;
    			
    			
    			if ($current_page != 1) 
    			{
    				echo '<a href="report.php?s=' . ($start - $display) . 
    				'&np=' . $num_pages . '" class=under>Previous</a> ';
    			}
    			
    			
    			for ($i = 1; $i <= $num_pages; $i++) 
    			{
    				if ($i != $current_page) 
    				{
    					echo '<a href="report.php?s=' . (($display * ($i - 1))) . 
    					'&np=' . $num_pages . '" class=under>' . $i . '</a> ';
    				} 
    				else 
    				{
    					echo $i . ' ';
    				}
    			}
    			
    			
    			if ($current_page != $num_pages) 
    			{
    				echo '<a href="report.php?s=' . ($start + $display) . 
    				'&np=' . $num_pages . '" class=under>Next</a>';
    			}
    									
    		} 
    		
    		
    		echo "<tr align=center class=tablehead><td width=20% class=tableborder><table><tr><td><b>NAME</b></td></tr></table></td>
    			<td width=50% class=tableborder><table><tr><td><b>TOPIC</b></td></tr></table></td>
    			<td width=10% class=tableborder><table><tr><td><b>REPLIES</b></td></tr></table></td>
    			<td width=20% class=tableborder><table><tr><td><b>DATE</b></td></tr></table></td></tr>";
    		
    		
    		while ($row = mysql_fetch_array($result, MYSQL_NUM)) 
    		{	
    			//puta
    								
    			$row[0] = '<font size=1>'.$row[0].'</font>';
      			echo "<tr><td width=20% class=tableborder align=center><table><tr><td><b><a href=\"\" class=\"under\">".strtolower($row[3])."</a><b></td></tr></table></td>
    			<td width=50% class=tableborder><table><tr><td><a href=\"reportview.php?pid={$row[2]}\" class=\"under\" style=\"font-weight: bold;\">$row[1]</a></td></tr></table></td>
    			<td width=10% class=tableborder align=center><table><tr><td>".replies(floor($row[2]))."</td></tr></table></td>
    			<td width=20% class=tableborder><table><tr><td>$row[0]</td></tr></table></td></tr>";  
    			
    		}		
    	
    		mysql_free_result ($result); 	
    	
    	} 
    	else 
    	{ 
    		echo '<h3>There are no records to show.</h3>'; 
    	}
    	
    	mysql_close(); 
    }
    
    //replies function
    function replies($postID)
    {
      $rcQuery = "SELECT count(postID) AS rowcount FROM comments WHERE postID=$postID";
      $rcResult = @mysql_query($rcQuery);
      if ($rcResult) 
      {
         return (@mysql_result($rcResult,0,'rowcount'));
      } 
      else 
      {
         die("Error with $rcQuery");
      }
    }
    the replies function is embedded in the adminpagination function...it worked fine though, but an error occured as follows:

    Warning: Missing argument 1 for replies() in Warning: Missing argument 1 for replies() in c:\inetpub\wwwroot\mysample\functions\library.php on line 321
    Error with SELECT count(postID) AS rowcount FROM comments WHERE postID=
    the code in line 321 is this
    Code:
    function replies($postID)
    now, where could be the problematic area??

    thanks

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's probably coming from:
    replies(floor($row[2]))

    After the while line echo out the value of $row[2], e.g
    while ($row = mysql_fetch_array($result, MYSQL_NUM))
    {
    //puta
    echo 'row2: '.$row[2];

    It's probably not set/empty.

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks....i tried but it only shows the topicID # of the specific thread...not the reply

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well that's the only place in the code you posted that replies() is called and as you're getting:
    SELECT count(postID) AS rowcount FROM comments WHERE postID=
    it means the passed in $postID was empty, which means floor($row[2]) was empty.
    Unless the error is coming from somewhere outside of the code you posted.

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i just called the admin function to the viewing page and that's it.....

  6. #6
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, the errors on line 321 but you only posted 123 lines. Sure there's no more?

  7. #7
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the other codes are also functions, i believe they have no relation to the two i posted

  8. #8
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then it must be replies(floor($row[2])) as that's the only place replies() is called.
    What does echo floor($row[2]); output?

  9. #9
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i modified the (floor($row[2])) part, removed the floor()....yes, that's the only place the replies() was called....it outputs the number of replies of a certain thread/message, but that error keeps on appearing.....with or without the floor()...

  10. #10
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have PHP 4.3.0 or above then you could try this:
    PHP Code:
    //replies function
    function replies($postID)
    {
        if(empty(
    $postID)) {
            echo 
    '<pre>';
            
    var_dump(debug_backtrace());
            echo 
    '</pre>';
        }
        
    //rest of function here

    and post the output. It should tell you the line number where the erronous call was made.

  11. #11
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no mysql query??

  12. #12
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that's covered by the line:
    //rest of function here


    I just added a bit to the top of the function, the rest of it still goes in there as was.

  13. #13
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    did that, but the error message is still there.....and it prints something like this

    array(2) {
    [0]=>
    array(4) {
    ["file"]=>
    string(49) "c:\inetpub\wwwroot\mysample\reportbodycontent.php"
    ["line"]=>
    int(24)
    ["function"]=>
    string(7) "replies"
    ["args"]=>
    array(0) {
    }
    }
    [1]=>
    array(4) {
    ["file"]=>
    string(38) "c:\inetpub\wwwroot\mysample\report.php"
    ["line"]=>
    int(58)
    ["args"]=>
    array(1) {
    [0]=>
    string(49) "c:\inetpub\wwwroot\mysample\reportbodycontent.php"
    }
    ["function"]=>
    string(7) "include"
    }
    }

  14. #14
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, it wasn't supposed to fix it, just debug it

    What's line 24 of c:\inetpub\wwwroot\mysample\reportbodycontent.php?

  15. #15
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whoaah!!!thanks a lot.....i got it now.....i forgot to remove the replies() from line 24 of reportbodycontent.php.....did that while experimenting.....your great man....it really worked great...thanks again man....

  16. #16
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •