where filter that uses a field name?

19 posts by 5 authors in: Forums > CMS Builder
Last Post: June 25, 2010   (RSS)

By Ryan - October 10, 2008 - edited: October 10, 2008

Hi, is it possable to use a where filter that uses a field name

This is what i have and it works fine but it's hard coded and i need something more flexable.

'where' => 'section LIKE "%Working at Heights%"',

I need something more like

'where' => 'section LIKE "%<?php echo $record[section] ?>%"',

Any Ideas, anyone


Nevermind found the answer

http://www.interactivetools.com/forum/forum.cgi?post=62927

Re: [ryan_dot] where filter that uses a field name?

By Dave - October 10, 2008

Hi Ryan_dot,

Glad you got it figured out!

Let us know if you need anything else.
Dave Edis - Senior Developer
interactivetools.com

Re: [ryan_dot] where filter that uses a field name?

By Dave - October 13, 2008

Hi ryan_dot,

Can you attach the viewer file to the post so I can take a look at the code?

Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] where filter that uses a field name?

By Ryan - October 14, 2008

Hi Dave, here is the page in question. Thanks
Attachments:

display.php 5K

Re: [ryan_dot] where filter that uses a field name?

By Dave - October 14, 2008

Thanks, there's a few ways to do this. To answer the basic question, it's only showing 1 record because you have:

'limit' => '1',

Which will limit the results to one only. And:

$plant_training_servicesRecord = @$plant_training_servicesRecords[0]; // get first record

Which gets just the first record and displays that. If you want to display multiple records from the service section you'd want to use a foreach like this:

<?php foreach ($plant_training_servicesRecords as $record): ?>
... show service record here ...
<?php endforeach ?>

Let me know if that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] where filter that uses a field name?

By Ryan - October 14, 2008

Hi Dave, i have edited the page to include some comments that explains better what im trying to do.

http://www.itsplanttech.com/plant-training-services/display.php?Plant-Training-1

using the plant services dropdown menu you can browse the first few downdown items

Basically i need that table at the bottom to filter based on the title of the current service selected. I could hard code the filter bit this would mean that i would have to create almost 20 extra pages. Users that add courses in the admin section use a dropdown menu that is linked to the title field in the services table creating a relationship between them.

I hope this makes more sense.


Attachments:

display_001.php 5K

Re: [ryan_dot] where filter that uses a field name?

By Dave - October 14, 2008

Hi ryan_dot,

How about this (changes in red):

//courses table which should filter to only show related courses
$escapedSection = mysql_real_escape_string( @$plant_training_servicesRecord['section'] );
list($coursesRecords, $coursesMetaData) = getRecords(array(
'tableName' => 'courses',
'where' => " section = '$escapedSection' ",
));


That will show courses where the section matches the section of the current services record.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] where filter that uses a field name?

By Ryan - October 14, 2008

Hi Dave, thank you so much that worked. I had to make a tiny change to suit my own needs

( @$plant_training_servicesRecord['name'] );

instead of

( @$plant_training_servicesRecord['section'] );

Cheers!

Re: [ryan_dot] where filter that uses a field name?

By studio-a - June 18, 2010 - edited: June 18, 2010

Hello,

I have been reading this thread and I think it has the solution we need, but I am not sure. If I understand correctly, this is the case:

Some of the names and titles have been changed for communication purposes.
Category = plant_training_services
Course = courses

-----------------------------------------------------------------------------------------------------------------------
01. There are TWO tables: (1) Category and the other (2) Course
02. Inside of the Courses Table is a dropdown menu which is populated by the other table’s (Category) field titled “catergory_name”
03. The Courses need to be sorted by the associated Category field in the List View page.
04. Is this Correct? If so, this is EXACTLY what we are trying to accomplish. However, filtering the Courses with Category is not working for us. We must be doing something wrong.

Is the code below setting up a way for the “where” statement to filter the Category Table's field with the Course list (the Courses per Category)?

$escapedSection = mysql_real_escape_string( @$plant_training_servicesRecord['section'] );

We have tried to use the URL filter as written below, but since the category_name is from another table it does not work. Is this correct?

listPage.php?catergory_name=catNameGoesHere

Any help is appreciated!

studio-a


P.S.
Jason assisted us in another matter for this same project at http://www.interactivetools.com/iforum/P81157#81157 if anyone is interested in reading additional information using two tables stucture. Now, IF we can only filter the listing!?