| Author |
Message |
Ramon
Joined: 12 Oct 2005 Posts: 473 Location: Hoogeveen, NL |
|
xfield filter |
|
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 ->
 |  | $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 
_________________
 |
|
| Tue Jan 15, 2008 10:43 am |
|
 |
Guest
|
|
|
Please login to hide the ads.
|
|
|
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2801 Location: Germany |
|
|
|
In inc/show.news.php change this:
 |  | foreach ($query as $bg => $row){ |
to this:
 |  | 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:
 |  | $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 |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1943 Location: US |
|
|
| Fri Jan 18, 2008 1:34 am |
|
 |
Ramon
Joined: 12 Oct 2005 Posts: 473 Location: Hoogeveen, NL |
|
|
|
_O_
This is awesome Yet again, thank you SO much
You're not only making the hacks, you're also making them better yourself and on top of that explaining how they work 
_________________
 |
|
| Fri Jan 18, 2008 12:41 pm |
|
 |
Ramon
Joined: 12 Oct 2005 Posts: 473 Location: Hoogeveen, NL |
|
|
|
So I started working on this today Got it figured out, but had to make some changes in order for it to work
Here's the renewed code for anyone who is interested
 |  | //----------------------------------
// 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
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 |
|
 |
jobringer
Joined: 24 Aug 2007 Posts: 4
|
|
|
|
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:
 |  | <form action="welcome.php" method="post">
Enter: <input type="text" name="datetype" />
<input type="submit" />
|
Results 'welcome.php' page:
 |  | <?php
$template = "browse";
$static = TRUE;
$xfieldfilter = array('date', '=', 'echo $_POST["datetype"]');
include("news/show_news.php");
?> |
|
|
| Wed Feb 13, 2008 11:30 pm |
|
 |
jobringer
Joined: 24 Aug 2007 Posts: 4
|
|
|
|
Fixed it myself! Proper code should be:
 |  | $xfieldfilter = array('date', '=', $_POST['datetype']); |
|
|
| Thu Feb 14, 2008 3:59 am |
|
 |
|