What does the following coding in search.php do?

Discussion forum for MOD Writers regarding MOD Development.
Locked
pubpro
Registered User
Posts: 165
Joined: Sat Oct 25, 2014 9:55 am

What does the following coding in search.php do?

Post by pubpro » Mon Dec 01, 2014 9:14 pm

Can someone briefly describe what each part of the following coding does? I know it contains the WHERE conditions for a table SELECT action, I am just having difficulty understanding the three parts:

Code: Select all

	if (sizeof($id_ary))
	{
		$sql_where .= $db->sql_in_set(($show_results == 'posts') ? 'p.post_id' : 't.topic_id', $id_ary);
		$sql_where .= (sizeof($ex_fid_ary)) ? ' AND (' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . ' OR f.forum_id IS NULL)' : '';
		$sql_where .= ($show_results == 'posts') ? $m_approve_fid_sql : str_replace(array('p.post_approved', 'p.forum_id'), array('t.topic_approved', 't.forum_id'), $m_approve_fid_sql);
	}

User avatar
RaythXC
Registered User
Posts: 150
Joined: Wed Jun 13, 2012 1:23 pm

Re: What does the following coding in search.php do?

Post by RaythXC » Tue Dec 02, 2014 12:53 am

if (sizeof($id_ary)) <-- This simply says that if anything is in $id_ary do the code between the { and }

$sql_where .= $db->sql_in_set(($show_results == 'posts') ? 'p.post_id' : 't.topic_id', $id_ary); <-- Assuming above is true, this then does a check with ($show_results == 'posts') and if is also true, then it does $db->sql_in_set('p.post_id') otherwise it does $db->sql_in_set('t.topic_id', $id_ary)

$sql_where .= (sizeof($ex_fid_ary)) ? ' AND (' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . ' OR f.forum_id IS NULL)' : ''; <-- Another check here. If $ex_fid_ary is set (ie not size 0), adds AND (' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . ' OR f.forum_id IS NULL) to the variable, otherwise adds nothing.

$sql_where .= ($show_results == 'posts') ? $m_approve_fid_sql : str_replace(array('p.post_approved', 'p.forum_id'), array('t.topic_approved', 't.forum_id'), $m_approve_fid_sql); <-- again adds to the variable depending on the value of $show_results. In this case, if it is equal to 'posts' then it adds the value of $m_approve_fid_sql otherwise it will add str_replace(array('p.post_approved', 'p.forum_id'), array('t.topic_approved', 't.forum_id'), $m_approve_fid_sql)

Every single one of these lines is simply adding text onto a string variable named $sql_where to generate part of an sql query.

User avatar
AmigoJack
Registered User
Posts: 5605
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: What does the following coding in search.php do?

Post by AmigoJack » Tue Dec 02, 2014 8:53 am

Now that would have been an explanation on how PHP works, without anything phpBB specific. Or do you have a question to phpBB?
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

pubpro
Registered User
Posts: 165
Joined: Sat Oct 25, 2014 9:55 am

Re: What does the following coding in search.php do?

Post by pubpro » Tue Dec 02, 2014 1:29 pm

As much as I appreciate the PHP explanation, my question was phpBB specific, i.e. the few lines of explanation that the programmer might have placed above the code lines to describe what the code is about to do.

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51834
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: What does the following coding in search.php do?

Post by Brf » Tue Dec 02, 2014 2:38 pm

You are asking for a general explanation of what those lines are doing there...

Basically, it says
"If we have a list of IDs to show"
"Show those posts or topics with those IDs"
"If we are showing IDs in a particular forum, only show those"
"Make sure the posts/topics are approved. If we are looking at posts, the selection criteria is in $m_approve_fid_sql, otherwise make sure the topic is approved".

pubpro
Registered User
Posts: 165
Joined: Sat Oct 25, 2014 9:55 am

Re: What does the following coding in search.php do?

Post by pubpro » Tue Dec 02, 2014 4:06 pm

Perfect, thank you. That helps.

Locked

Return to “[3.0.x] MOD Writers Discussion”