Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
where filter that uses a field name?

 

 


ryan_dot
User

Oct 10, 2008, 12:00 PM

Post #1 of 9 (2884 views)
Shortcut
where filter that uses a field name? Can't Post

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


http://www.westendpropertysales.com
http://www.eadiemcfarland.co.uk
http://www.macneanrestaurant.com
http://www.theclocktower.ie


(This post was edited by ryan_dot on Oct 10, 2008, 12:12 PM)


Dave
Staff / Moderator


Oct 10, 2008, 1:48 PM

Post #2 of 9 (2880 views)
Shortcut
Re: [ryan_dot] where filter that uses a field name? [In reply to] Can't Post

Hi Ryan_dot,

Glad you got it figured out!

Let us know if you need anything else.

Dave Edis - Senior Developer
interactivetools.com


ryan_dot
User

Oct 10, 2008, 2:32 PM

Post #3 of 9 (2879 views)
Shortcut
Re: [Dave] where filter that uses a field name? [In reply to] Can't Post

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
/* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
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',


));


?>


http://www.westendpropertysales.com
http://www.eadiemcfarland.co.uk
http://www.macneanrestaurant.com
http://www.theclocktower.ie


Dave
Staff / Moderator


Oct 13, 2008, 10:45 AM

Post #4 of 9 (2837 views)
Shortcut
Re: [ryan_dot] where filter that uses a field name? [In reply to] Can't Post

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


ryan_dot
User

Oct 14, 2008, 7:23 AM

Post #5 of 9 (2824 views)
Shortcut
Re: [Dave] where filter that uses a field name? [In reply to] Can't Post

Hi Dave, here is the page in question. Thanks


http://www.westendpropertysales.com
http://www.eadiemcfarland.co.uk
http://www.macneanrestaurant.com
http://www.theclocktower.ie
Attachments: display.php (4.98 KB)


Dave
Staff / Moderator


Oct 14, 2008, 10:38 AM

Post #6 of 9 (2796 views)
Shortcut
Re: [ryan_dot] where filter that uses a field name? [In reply to] Can't Post

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


ryan_dot
User

Oct 14, 2008, 12:26 PM

Post #7 of 9 (2778 views)
Shortcut
Re: [Dave] where filter that uses a field name? [In reply to] Can't Post

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.




http://www.westendpropertysales.com
http://www.eadiemcfarland.co.uk
http://www.macneanrestaurant.com
http://www.theclocktower.ie
Attachments: display.php (4.04 KB)


Dave
Staff / Moderator


Oct 14, 2008, 12:48 PM

Post #8 of 9 (2777 views)
Shortcut
Re: [ryan_dot] where filter that uses a field name? [In reply to] Can't Post

Hi ryan_dot,

How about this (changes in red):


Code
  //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


ryan_dot
User

Oct 14, 2008, 1:31 PM

Post #9 of 9 (2769 views)
Shortcut
Re: [Dave] where filter that uses a field name? [In reply to] Can't Post

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!


http://www.westendpropertysales.com
http://www.eadiemcfarland.co.uk
http://www.macneanrestaurant.com
http://www.theclocktower.ie