Forum Index
RegisterSearchFAQMemberlistUsergroupsLog in
xfield filter

 
Reply to topic    Forum Index » Help View previous topic
View next topic
xfield filter
Author Message
Ramon



Joined: 12 Oct 2005
Posts: 473
Location: Hoogeveen, NL

Post xfield filter Reply with quote
Following the topic about searching in xfields I quess the thing that i'm about to ask is possible.

Is it possible to have an option like the next ->

Code:
  $number = "3"
  $category = "5"
  $xfieldfilter['rating'] = '9';

include 'path/to/show_news.php';


I know i'm asking quite a lot, but I think this feature could be really promising and very handy Smile

_________________
Tue Jan 15, 2008 10:43 am View user's profile Send private message Visit poster's website
Guest








Please login to hide the ads.

FI-DD
Admin


Joined: 22 Sep 2005
Posts: 2801
Location: Germany

Post Reply with quote
In inc/show.news.php change this:
Code:
foreach ($query as $bg => $row){


to this:
Code:
function xfield_filter($id){
global $xfieldfilter;

   $return = true;
   $path_to_xfields = '../data/xfields-data.txt';
   $xfield_data = file($path_to_xfields);
   foreach($xfield_data as $line){
      $line_arr = explode("|>|", $line);
      if($line_arr[0] == $id){
         $all_xfields = explode("||", $line_arr[1]);
         foreach($all_xfields as $single_xfield){
            $my_xfield = explode("|", $single_xfield);
            if($my_xfield[0] == $xfieldfilter[0]){
               if($xfieldfilter[1] == '='){
                  if(trim($my_xfield[1]) == $xfieldfilter[2]){
                     $return = false;
                  }
               }
               if($xfieldfilter[1] == '<'){
                  if(trim($my_xfield[1]) < $xfieldfilter[2]){
                     $return = false;
                  }
               }
               if($xfieldfilter[1] == '>'){
                  if(trim($my_xfield[1]) > $xfieldfilter[2]){
                     $return = false;
                  }
               }
               if($xfieldfilter[1] == '<='){
                  if(trim($my_xfield[1]) <= $xfieldfilter[2]){
                     $return = false;
                  }
               }
               if($xfieldfilter[1] == '>='){
                  if(trim($my_xfield[1]) >= $xfieldfilter[2]){
                     $return = false;
                  }
               }
            }
            else{
               continue;
            }
         }
      }
      else{
         continue;
      }
   }
   
   return $return;

}

foreach ($query as $bg => $row){

if(xfield_filter($row['id'])){
   continue;
}


Use something like this in your include code:
Code:
$xfieldfilter = array('my_xfield', '>', '5');


This will only show news which have an xfield with a value bigger than 5.

"my_xfield" is the name of the xfield, 5 is the value of the xfield and '>' is the operator. You can use "<, >, <=, >=, =" as operators. Of course, if you don't have numbers in your xfield only "=" will work.
Thu Jan 17, 2008 9:00 pm View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1943
Location: US

Post Reply with quote
Shocked Surprised

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Fri Jan 18, 2008 1:34 am View user's profile Send private message Visit poster's website AIM Address
Ramon



Joined: 12 Oct 2005
Posts: 473
Location: Hoogeveen, NL

Post Reply with quote
_O_

This is awesome Cool Yet again, thank you SO much Exclamation

You're not only making the hacks, you're also making them better yourself and on top of that explaining how they work Cool

_________________
Fri Jan 18, 2008 12:41 pm View user's profile Send private message Visit poster's website
Ramon



Joined: 12 Oct 2005
Posts: 473
Location: Hoogeveen, NL

Post Reply with quote
So I started working on this today Smile Got it figured out, but had to make some changes in order for it to work Smile

Here's the renewed code for anyone who is interested

Code:
//----------------------------------
// START XFIELDFILTER HACK BY FI-DD
//----------------------------------

if(isset($xfieldfilter)){

function xfield_filter($id){
global $xfieldfilter;

   $return = true;
   $path_to_xfields = '../data/xfields-data.txt';
   $xfield_data = file($path_to_xfields);
   foreach($xfield_data as $line){
      $line_arr = explode("|>|", $line);
      if($line_arr[0] == $id){
         $all_xfields = explode("||", $line_arr[1]);
         foreach($all_xfields as $single_xfield){
            $my_xfield = explode("|", $single_xfield);
            if($my_xfield[0] == $xfieldfilter[0]){
               if($xfieldfilter[1] == '='){
                  if(trim($my_xfield[1]) == $xfieldfilter[2]){
                     $return = false;
                  }
               }
               if($xfieldfilter[1] == '<'){
                  if(trim($my_xfield[1]) < $xfieldfilter[2]){
                     $return = false;
                  }
               }
               if($xfieldfilter[1] == '>'){
                  if(trim($my_xfield[1]) > $xfieldfilter[2]){
                     $return = false;
                  }
               }
               if($xfieldfilter[1] == '<='){
                  if(trim($my_xfield[1]) <= $xfieldfilter[2]){
                     $return = false;
                  }
               }
               if($xfieldfilter[1] == '>='){
                  if(trim($my_xfield[1]) >= $xfieldfilter[2]){
                     $return = false;
                  }
               }
            }
            else{
               continue;
            }
         }
      }
      else{
         continue;
      }
   }
   
   return $return;

} }

foreach ($query as $bg => $row){

if(isset($xfieldfilter)){
   if(xfield_filter($row['id'])){
      continue;
   }
}

//----------------------------------
// END XFIELDFILTER HACK BY FI-DD
//----------------------------------


Works like a charm Embarassed

I used it for selecting articles by country on http://fminside.nl/gidsen/ just so you can have a look at how powerfull this is right here.

_________________
Thu Jan 24, 2008 12:14 am View user's profile Send private message Visit poster's website
jobringer



Joined: 24 Aug 2007
Posts: 4

Post Reply with quote
Great Script! I'm using this on my website to filter out various xfields and I was wondering if I could use PHP POST in my include file.

I have two pages, one with a drop down, and another for the results. The input value name="datetype".

When I put the PHP POST in the include tag it does not spit back any results. An example of my code is below.

I think what is happening is the echo $_POST["datetype"]; is not posting correctly and therefore no value is being inputed in that xfieldfilter area .

Any help?

FORM:
Code:
<form action="welcome.php" method="post">
Enter: <input type="text" name="datetype" />
<input type="submit" />


Results 'welcome.php' page:
Code:
<?php
$template = "browse";
$static = TRUE;
$xfieldfilter = array('date', '=', 'echo $_POST["datetype"]');

include("news/show_news.php");
?>

Wed Feb 13, 2008 11:30 pm View user's profile Send private message
jobringer



Joined: 24 Aug 2007
Posts: 4

Post Reply with quote
Fixed it myself! Proper code should be:

Code:
$xfieldfilter = array('date', '=', $_POST['datetype']);

Thu Feb 14, 2008 3:59 am View user's profile Send private message
Display posts from previous:    
Reply to topic    Forum Index » Help All times are GMT + 1 Hour
Page 1 of 1

 
Jump to: 
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 cannot attach files in this forum
You can download files in this forum



Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Music Lyrics.