phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

Adding some infos to the search result


 
Search this topic... | Search MOD Requests... | Search Box
Register or Login to Post    Index » MOD Requests  Previous TopicPrint TopicNext Topic
Author Message
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Thu Apr 08, 2010 1:21 pm 
Post subject: Adding some infos to the search result

Hi,

I have two additional fields in posting and viewtopic.
It is "maskin" and "maskinnr".
In viewtopic those are pulled like this:
Code:
$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_phoogle_map_center, u.user_phoogle_allow, u.user_phoogle_show_me, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, u.consumption_hours_start, u.consumption_hours_current, u.consumption_liters, u.consumption_machine, u.user_birthday, u.user_next_birthday_greeting, u.user_active, u.user_allow_viewonline, u.user_session_time, u.user_country, p.*,  pt.post_text, pt.post_subject, pt.no_piu, pt.post_maskin, pt.post_maskinnr, pt.bbcode_uid, pt.quiz_answer, t.k_id
   FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt, " . TOPICS_TABLE. " t
   WHERE p.topic_id = $topic_id
      $limit_posts_time
      AND pt.post_id = p.post_id
      AND u.user_id = p.poster_id
      AND t.topic_id = $topic_id
   ORDER BY p.post_time $post_time_order ".$_limit;


Code:
   $post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : '';
   $post_maskin = ( $postrow[$i]['post_maskin'] != '' ) ? '<b>'. $lang['Maskin_information'] .': </b> '. $postrow[$i]['post_maskin'] : '';
   $post_maskinnr = ( $postrow[$i]['post_maskinnr'] != '' ) ? '<b>'. $lang['Maskinnr_information'] .': </b> '. $postrow[$i]['post_maskinnr'] : '';


Code:
   //
   // Replace naughty words
   //
   if (count($orig_word))
   {
      $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
      $post_maskin = preg_replace($orig_word, $replacement_word, $post_maskin);
      $post_maskinnr = preg_replace($orig_word, $replacement_word, $post_maskinnr);


Code:
      'POST_MASKIN' => $post_maskin,
      'POST_MASKINNR' => $post_maskinnr,


In the DB it is post_maskin and post_maskinnr in the table phpbb_posts_text

I would like to show those fields in the search result.

Can anyone help me with this?

/Holger
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Wed Jun 02, 2010 8:08 am 
Post subject: Re: Adding some infos to the search result

Nobody?
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Wed Sep 15, 2010 8:03 am 
Post subject: Re: Adding some infos to the search result

Nobody? icon_sad.gif
Back to top
Salvatos
Board Member



Joined: 19 Feb 2009

Posts: 417
Location: Québec


flag
PostPosted: Wed Sep 15, 2010 11:06 am 
Post subject: Re: Adding some infos to the search result

If you already have the query and the template VARS, what part do you need help with?
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Wed Sep 15, 2010 11:16 am 
Post subject: Re: Adding some infos to the search result

Sorry, I am not so good in PHP/mysql! icon_redface.gif
Those u., pt., p.*, u., u2. and so on confuses me!

I have this in search.php:
Code:
   //
   // Look up data ...
   //
   if ( $search_results != '' )
   {
      if ( $show_results == 'posts' )
      {
         $sql = "SELECT pt.post_text, pt.bbcode_uid, pt.post_subject, p.*, f.forum_id, f.forum_name, t.*, u.username, u.user_id, u.user_sig, u.user_sig_bbcode_uid
            FROM " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt
            WHERE p.post_id IN ($search_results)
               AND pt.post_id = p.post_id
               AND f.forum_id = p.forum_id
               AND p.topic_id = t.topic_id
               AND p.poster_id = u.user_id";
      }
      else
      {
         $sql = "SELECT t.*, f.forum_id, f.forum_name, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
            FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
            WHERE t.topic_id IN ($search_results)
               AND t.topic_poster = u.user_id
               AND f.forum_id = t.forum_id
               AND p.post_id = t.topic_first_post_id
               AND p2.post_id = t.topic_last_post_id
               AND u2.user_id = p2.poster_id";
      }


Do I just have to amend the SELECT with
Code:
, pt.post_maskin, pt.post_maskinnr

?

What about the
$template->assign_vars(array(
?
Back to top
Salvatos
Board Member



Joined: 19 Feb 2009

Posts: 417
Location: Québec


flag
PostPosted: Wed Sep 15, 2010 1:52 pm 
Post subject: Re: Adding some infos to the search result

Holger wrote:
Do I just have to amend the SELECT with...?

Yes, but I would put it after pt.post_subject for clarity, so that the tables are grouped. You see, the way this works is that "pt" represents the posts_text table, as set in the query (FROM " . POSTS_TEXT_TABLE . " pt), so what the query means, for instance, with "pt.post_subject" is: select column post_subject from POSTS_TEXT_TABLE (posts_text).

Next you're going to have to edit the part around "if ( count($orig_word) )" to perform the actual operations:
Code:
                    if ( count($orig_word) )
                    {
                        $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
                        $post_subject = ( $searchset[$i]['post_subject'] != "" ) ? preg_replace($orig_word, $replacement_word, $searchset[$i]['post_subject']) : $topic_title;
                        $post_maskin = ( $searchset[$i]['post_maskin'] != '' ) ? '<b>'. $lang['Maskin_information'] .': </b> '. preg_replace($orig_word, $replacement_word, $searchset[$i]['post_maskin']) : '';
                        $post_maskinnr = ( $searchset[$i]['post_maskinnr'] != '' ) ? '<b>'. $lang['Maskinnr_information'] .': </b> '. preg_replace($orig_word, $replacement_word, $searchset[$i]['post_maskinnr']) : '';

                        $message = preg_replace($orig_word, $replacement_word, $message);
                    }
                    else
                    {
                        $post_subject = ( $searchset[$i]['post_subject'] != '' ) ? $searchset[$i]['post_subject'] : $topic_title;
                        $post_maskin = ( $searchset[$i]['post_maskin'] != '' ) ? '<b>'. $lang['Maskin_information'] .': </b> '. $searchset[$i]['post_maskin'] : '';
                        $post_maskinnr = ( $searchset[$i]['post_maskinnr'] != '' ) ? '<b>'. $lang['Maskinnr_information'] .': </b> '. $searchset[$i]['post_maskinnr'] : '';
                    }

Notice we're using $searchset here for the query instead of $postrow. Also, there are two "if ( count($orig_word) )": one for results shown as posts, and one for results as topics. I'm assuming we're working on the first option only since there's no $post_subject in the second one, but I could be wrong since I don't really know what your MOD does and $post_subject may very well be completely irrelevant. Otherwise, duplicating this step isn't too tough but you'll also have to edit the second SQL query accordingly and create another batch of template vars around 1249.

And then adding template vars is easy as pie, just add this
Code:
      'POST_MASKIN' => $post_maskin,
      'POST_MASKINNR' => $post_maskinnr,

within all necessary $template->assign_block_vars (make sure the lines are ended by a comma, except the last one, so if you're pasting this as the last two variables created, remove the last comma and make sure that the variable that was previously the last one now has a comma). The tough part here is determining where you'll need it, as search.php has all kinds of ifs and elses that may or may not apply to your MOD. In an unedited search.php, you're probably looking at line 1039 (showing results as posts). That's right before this:
Code:
            else
            {
                $message = '';



I guess that's all I can say for now, hopefully you can see for yourself if you need to move or add stuff to this. Otherwise let us know what's not working and we'll see what we can do icon_smile.gif


P. S. Please excuse any typos, the forum's font is unusually small on Ubuntu and I didn't get a whole lot of sleep so I might have missed some.
Back to top
Holger
Board Member



Joined: 19 Jan 2009

Posts: 509
Location: Hanover


flag
PostPosted: Wed Sep 15, 2010 1:55 pm 
Post subject: Re: Adding some infos to the search result

This is soooo cool! Thank you so much! I will try this!
Back to top
Display posts from previous:   
Register or Login to Post    Index » MOD Requests  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0130 seconds using 15 queries. (SQL 0.0022 Parse 0.0003 Other 0.0105)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo