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: [Dave] where filter that uses a field name?

By Ryan - October 10, 2008

Hi Dave, i thought i had it but i've still got an issue

Can you see what im doing wrong? I have two tables one for services and one for courses and im trying to include courses that relate to that services in a kind of sub section at the bottom of the services page.

http://www.itsplanttech.com/plant-training-services/display.php?Plant-Training-1&section=Plant%20Training

As you can see it will display the courses but will not display anything but the first service record from services.

Any ideas,

<?php

require_once "/home/content/i/t/s/itsplanttech/html/cmsadmin/lib/viewer_functions.php";

list($plant_training_servicesRecords, $plant_training_servicesMetaData) = getRecords(array(
'tableName' => 'plant_training_services',
//'where' => whereRecordNumberInUrl(1),
// 'limit' => '1',
));
$plant_training_servicesRecord = @$plant_training_servicesRecords[0]; // get first record


list($coursesRecords, $coursesMetaData) = getRecords(array(
'tableName' => 'courses',


));


?>

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!