Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
Guardian2003
Site Admin


Joined: Aug 28, 2003
Posts: 6792
Location: Ha Noi, Viet Nam

PostPosted: Fri Aug 12, 2005 5:59 am Reply with quote

I have a forum center block I'm using courtesy of lorkan themes - it came packaged with there theme.
I would like to restrict specific forum categories from showing in the results but have not got a clue when it come to mysql.
I did try to compare it with another center block I have but the sql calls seem completely different.
As the code contains some rather long lines I have a link below to a plain text file is anyone can help me out here. Only registered users can see links on this board! Get registered or login!

I noticed this file uses $dbi as against my other I was using for comparison which uses $db - I seem to remember that using $dbi is a bit naughty?
If so, what are my options?
 
View user's profile Send private message Send e-mail
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17077

PostPosted: Fri Aug 12, 2005 3:19 pm Reply with quote

Around line 37 is
Code:
$result = $db->sql_query( "SELECT t.topic_id, f.forum_name, f.forum_id, t.topic_last_post_id, t.topic_title, t.topic_poster, t.topic_views, t.topic_replies, t.topic_moved_id FROM ".$prefix."_bbtopics t, ".$prefix."_bbforums f where t.forum_id=f.forum_id ORDER BY topic_last_post_id DESC" );

Modify it to
Code:
$catIdsToSkip = '1,2,3';

$result = $db->sql_query( "SELECT t.topic_id, f.forum_name, f.forum_id, t.topic_last_post_id, t.topic_title, t.topic_poster, t.topic_views, t.topic_replies, t.topic_moved_id FROM ".$prefix."_bbtopics t, ".$prefix."_bbforums f where f.cat_id NOT IN($catIdsToSkip) AND t.forum_id=f.forum_id ORDER BY topic_last_post_id DESC" );
 
View user's profile Send private message
Guardian2003
PostPosted: Sat Aug 13, 2005 3:40 am Reply with quote

Thank you for taking the time to look at that!
Unfortunately it didnt work, the result was the block failing to load on the page with the rest of the 'center' page missing after it i.e. no news articles. Left blocks where fine etc.
Looking at your example above, I see on the last line the use of 'where f .cat_id' - as I am trying to learn something in this process, could this be the cause of the problem?
I see no other reference to 'f. cat_id' anywhere - how does the block code know what this is or how to use it?
I am assuming (theres that dangerous word again) the SELECT statement means, 'retrieve from the table' so I would need to add f. topic_id to that ?
 
Raven
PostPosted: Sat Aug 13, 2005 7:41 am Reply with quote

Check your code again because I just tested this and it worked w/o any error.
 
Guardian2003
PostPosted: Sat Aug 13, 2005 9:19 am Reply with quote

I just copied and pasted it from above but I'll check it again - may well be 'operator error' lol.
 
Guardian2003
PostPosted: Sat Aug 13, 2005 9:53 am Reply with quote

DOH!
Now I'm left wondering how you guys dont get confused between files - I only had 2 to worry about and I posted a link to the wrong file Embarassed

The original code is actually;
Code:
$result = sql_query( "SELECT topic_id, forum_id, topic_last_post_id, topic_title, topic_poster, topic_views, topic_replies, topic_moved_id FROM ".$prefix."_bbtopics ORDER BY topic_last_post_id DESC", $dbi );

while( list( $topic_id, $forum_id, $topic_last_post_id, $topic_title, $topic_poster, $topic_views, $topic_replies, $topic_moved_id ) = sql_fetch_row( $result, $dbi ) )


Sorry Raven for wasting your valuable time.
File updated for the link in my first post.
 
Raven
PostPosted: Sat Aug 13, 2005 10:19 am Reply with quote

Were you this much trouble as a child ROTFL ?
Code:
<?php


########################################################################
# PHP-Nuke Block: Helius Center Forum Block v.9                        #
# Made for PHP-Nuke 6.* and the phpbb2 Nuke port 2.06 only             #
#                                                                      #
# Made by coldblooded http://www.nukemods.com                          #
########################################################################
# This program is free software. You can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License.       #
# If you modify this, let me know for fun. =)                          #
########################################################################
## Modified by Gaylen Fraley (aka Raven) 8/13/2005 to allow blocking  ##
## certain categories. Also changed $dbi calls to $db                 ##
########################################################################

if (eregi("block-PH2BLUE_CB-Forums.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}
global $user_prefix, $db, $theme, $sitename, $admin, $bgcolor1, $bgcolor2, $bgcolor4;

$HideViewReadOnly = 1;
$Last_New_Topics  = 5;
$ThemeSel = get_theme();
$show = "  <tr>
    <td bgcolor=\"#FABF0D\" height=\"25\" colspan=\"6\" align=\"center\" background=\"themes/$ThemeSel/forums/images/top_center.gif\"></td>
  </tr>
</table></td>
        </tr>
      </table></td>
  </tr>
</table>";

$Count_Topics = 0;
$Topic_Buffer = "";

$catIdsToSkip = '1,2,3';
$sql = "SELECT t.topic_id, f.forum_id, t.topic_last_post_id, t.topic_title, t.topic_poster, t.topic_views, t.topic_replies, t.topic_moved_id FROM ".$user_prefix."_bbtopics t, ".$user_prefix."_bbforums f where f.cat_id NOT IN($catIdsToSkip) AND t.forum_id=f.forum_id ORDER BY topic_last_post_id DESC";
$result = $db->sql_query($sql);

while( list( $topic_id, $forum_id, $topic_last_post_id, $topic_title, $topic_poster, $topic_views, $topic_replies, $topic_moved_id ) = $db->sql_fetchrow( $result) )

{
   $skip_display = 0;
   if( $HideViewReadOnly == 1 )
   {
      $result2 = $db->sql_query( "SELECT auth_view, auth_read FROM ".$user_prefix."_bbforums where forum_id = '$forum_id'");
      list( $auth_view, $auth_read ) = $db->sql_fetchrow( $result2 );
      if( ( $auth_view != 0 ) or ( $auth_read != 0 ) ) { $skip_display = 1; }
   }

   if( $topic_moved_id != 0 )
   {
     // Shadow Topic !!
      $skip_display = 1;
   }

   if( $skip_display == 0 )
   {
     $Count_Topics += 1;

$result2 = $db->sql_query("SELECT username, user_id FROM ".$user_prefix."_users where user_id='$topic_poster'");
list($username, $user_id)=$db->sql_fetchrow($result2);
$avtor=$username;
$sifra=$user_id;

$result3 = $db->sql_query("SELECT poster_id, FROM_UNIXTIME(post_time,'%m/%d/%Y at %H:%i') as post_time FROM ".$user_prefix."_bbposts where post_id='$topic_last_post_id'");
list($poster_id, $post_time)=$db->sql_fetchrow($result3);

$result4 = $db->sql_query("SELECT username, user_id FROM ".$user_prefix."_users where user_id='$poster_id'");
list($username, $user_id)=$db->sql_fetchrow($result4);

                         $viewlast .="  <tr>
    <td height=\"34\" nowrap bgcolor=\"#EAEDF4\" class=\"row1\"><img src=\"themes/$ThemeSel/forums/images/folder_new.gif\" border=\"0\" /></td>
    <td width=\"100%\" bgcolor=\"#EAEDF4\" class=\"row1\">&nbsp;<a href=\"forums.html?file=viewtopic&t=$topic_id#$topic_last_post_id\">$topic_title</a></td>
    <td align=\"center\" bgcolor=\"#F8F9FA\" class=\"row2\">$topic_replies</td>
    <td align=\"center\" bgcolor=\"#EAEDF4\" class=\"row3\"><a href=\"profile-.html$sifra\">$avtor</a></td>
    <td align=\"center\" bgcolor=\"#F8F9FA\" class=\"row2\">$topic_views</td>
    <td align=\"center\" nowrap bgcolor=\"#EAEDF4\" class=\"row3\"><font size=\"-2\"><i>&nbsp;&nbsp;$post_time&nbsp;</i></font><br>
      <a href=\"profile-.html$user_id\">$username</a>&nbsp;<a href=\"forums.html?file=viewtopic&p=$topic_last_post_id#$topic_last_post_id\"><img src=\"themes/$ThemeSel/forums/images/icon_minipost_new.gif\" border=\"0\" alt=\"Latest Post\"></a></td>
  </tr>";
}

   if( $Last_New_Topics == $Count_Topics ) { break 1; }

}

    $content .= "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td bgcolor=\"#567188\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
        <tr>
          <td><table width=\"100%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\">
  <tr>
    <th height=\"25\" colspan=\"2\" align=\"center\" nowrap background=\"themes/$ThemeSel/forums/images/top_center.gif\" class=\"thcornerl\"><font color=\"#FABF0D\"><strong>Topics</strong></font></th>
    <th width=\"50\" align=\"center\" nowrap background=\"themes/$ThemeSel/forums/images/top_center.gif\" class=\"thtop\"><font color=\"#FABF0D\"><strong>&nbsp;Replies&nbsp;</strong></font></th>
    <th width=\"100\" align=\"center\" nowrap background=\"themes/$ThemeSel/forums/images/top_center.gif\" class=\"thtop\"><font color=\"#FABF0D\"><strong>&nbsp;Author&nbsp;</strong></font></th>
    <th width=\"50\" align=\"center\" nowrap background=\"themes/$ThemeSel/forums/images/top_center.gif\" class=\"thtop\"><font color=\"#FABF0D\"><strong>&nbsp;Views&nbsp;</strong></font></th>
    <th align=\"center\" nowrap background=\"themes/$ThemeSel/forums/images/top_center.gif\" class=\"thcornerr\"><font color=\"#FABF0D\"><strong>&nbsp;Last Post&nbsp;</strong></font></th>
  </tr>";
    $content .= "$viewlast";

 $content .= "$show";

?>


Last edited by Raven on Sun Aug 14, 2005 6:36 am; edited 2 times in total 
Guardian2003
PostPosted: Sat Aug 13, 2005 10:53 am Reply with quote

I was much worse as a child - apparently I used to like burying my spectacles in the park sandpit and then forgetting where I had buried then - no improvement on my memory since lol.
 
Raven
PostPosted: Sat Aug 13, 2005 10:59 am Reply with quote

Better than burying you testacles ROTFL
 
Guardian2003
PostPosted: Sat Aug 13, 2005 11:13 am Reply with quote

LOL yeah but that might have been cheaper for my mother at the time lol

I think I'll come back to this tomorrow - seems it is just not my day today with one thing or another.....
OK I uploaded this code into a new block after deleting the original from the server.
The block itself load fine and the whole front page loads fine - only there is no content at all inside the center block, that is to say, no forum posts at all.
I tried it with both the forum cat (17) I need to exclude and with '0' and with no value at all.
Just in case, I tried it with IE and FF - see what I mean, not my day today lol.

Many thanks Raven for spending time on this, it IS appreciated but I'll revisit the problem after some sleep, I probbly did something stupid (again) and have not realised yet.
 
Raven
PostPosted: Sat Aug 13, 2005 11:17 am Reply with quote

I did not test this at all. I just modified it on the fly. It sounds like you aren't getting any results back on your query. I'll do some testing a little later.
 
Guardian2003
PostPosted: Sat Aug 13, 2005 4:01 pm Reply with quote

Thanks, much appreciated.
 
Raven
PostPosted: Sat Aug 13, 2005 9:05 pm Reply with quote

It's fixed and I edited my post above. Recopy the code.
 
Guardian2003
PostPosted: Sun Aug 14, 2005 2:10 am Reply with quote

Thats much better Raven, thank you very much.
How do I amend that code to show the forum post subject?
At the moment it is displaying a 5 digit number. You can see it here Only registered users can see links on this board! Get registered or login!
 
Raven
PostPosted: Sun Aug 14, 2005 6:36 am Reply with quote

Quote:
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime!

Reference the following code excerpts
Code:
$sql = "SELECT t.topic_id, f.forum_name, f.forum_id, t.topic_last_post_id, t.topic_title, t.topic_poster, t.topic_views, t.topic_replies, t.topic_moved_id FROM ".$user_prefix."_bbtopics t, ".$user_prefix."_bbforums f where f.cat_id NOT IN($catIdsToSkip) AND t.forum_id=f.forum_id ORDER BY topic_last_post_id DESC";


while( list( $topic_id, $forum_id, $topic_last_post_id, $topic_title, $topic_poster, $topic_views, $topic_replies, $topic_moved_id ) = $db->sql_fetchrow( $result) )

{

When using the list function, the variable order must be the same as the variable order in your SELECT statement. If you look closely you will see that the SELECT statement references a column called f.forum_name, yet that column is missing from the list function. So, everything listed after that is 1 column off. Since f.forum_name is never used in that block code, just delete it from your SELECT statement, like this
Code:
$sql = "SELECT t.topic_id, f.forum_id, t.topic_last_post_id, t.topic_title, t.topic_poster, t.topic_views, t.topic_replies, t.topic_moved_id FROM ".$user_prefix."_bbtopics t, ".$user_prefix."_bbforums f where f.cat_id NOT IN($catIdsToSkip) AND t.forum_id=f.forum_id ORDER BY topic_last_post_id DESC";

Now the SELECT and list are in sync. I have corrected the code above also.
 
Guardian2003
PostPosted: Sun Aug 14, 2005 7:00 am Reply with quote

Thank you for the explanation and insight - lesson 1 learnt.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©