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 19 (4847 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

[i]
[url]http://www.westendpropertysales.com[/url]
[url]http://www.eadiemcfarland.co.uk[/url]
[url]http://www.macneanrestaurant.com[/url]
[url]http://www.theclocktower.ie[/url]
[/i]

(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 19 (4843 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 19 (4842 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',


));


?>

[i]
[url]http://www.westendpropertysales.com[/url]
[url]http://www.eadiemcfarland.co.uk[/url]
[url]http://www.macneanrestaurant.com[/url]
[url]http://www.theclocktower.ie[/url]
[/i]


Dave
Staff / Moderator


Oct 13, 2008, 10:45 AM

Post #4 of 19 (4800 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 19 (4787 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

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


Dave
Staff / Moderator


Oct 14, 2008, 10:38 AM

Post #6 of 19 (4759 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 19 (4741 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.



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


Dave
Staff / Moderator


Oct 14, 2008, 12:48 PM

Post #8 of 19 (4740 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 19 (4732 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!

[i]
[url]http://www.westendpropertysales.com[/url]
[url]http://www.eadiemcfarland.co.uk[/url]
[url]http://www.macneanrestaurant.com[/url]
[url]http://www.theclocktower.ie[/url]
[/i]


studio-a
User

Jun 18, 2010, 12:13 PM

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

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)?


Code
  $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?


Code
   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!?


(This post was edited by studio-a on Jun 18, 2010, 12:54 PM)


chris
Staff


Jun 18, 2010, 1:50 PM

Post #11 of 19 (1889 views)
Shortcut
Re: [studio-a] where filter that uses a field name? [In reply to] Can't Post

Hi studio-a,

I think the simplest solution is to use the category's record number in the URL. You can have both the category's record number and name in the URL for SEO/readability purposes, just like how detail pages work.

Can you please post the complete PHP source code for the page you're working on?
Chris


studio-a
User

Jun 18, 2010, 7:29 PM

Post #12 of 19 (1877 views)
Shortcut
Re: [chris] where filter that uses a field name? [In reply to] Can't Post

Hi Chris,

Thanks for getting back with us. We have uploaded the php file for the test listing page. You will note a variety of php lines of code rendered out.

We are interested in using the URL with the category number and name with the SEO/readability.

BELOW IS OUR SETUP.

table 01 = service_categories
textfield within this table = category_name
textbox within this table = summary

table 02 = service_titles
droplist within this table = category (this is being dynamically populated from table 01 textfield category_name)
textfield within this table = service_title
textbox within this table = description

Our objective is to create List Pages for EACH Service Category while displaying the category_name and summary at the top of each page followed by the list of service_titles and descriptions associated with the dynamically created category_name(s) grouping. In addition, we will need to include the page links.

As you can see within the php test page we have the information for the page created, we're just not sure how to query the database since we are using two tables. Let me ask, "Using two tables for this dynamic menu setup - is this a good strategy? Is there a better way to offer the client a dynamic way of creating interactive menus?"

Thanks for your help and time. We look forward to hearing your reply!

studio-a


(This post was edited by studio-a on Jun 19, 2010, 3:21 AM)
Attachments: list.test.php (3.38 KB)


Jason
Staff


Jun 21, 2010, 10:15 AM

Post #13 of 19 (1634 views)
Shortcut
Re: [studio-a] where filter that uses a field name? [In reply to] Can't Post

Hi,

To clarify, on your page, are you wanting to display all service_categories records? Or just one that has been selected?

Also, how are you associating a service_title record with a category? Is there a category field in the service_titles table? If so, what are you storing there, a number or a name?

Let me know and we'll see if we can get this sorted out for you.
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/ 


studio-a
User

Jun 21, 2010, 10:34 AM

Post #14 of 19 (1632 views)
Shortcut
Re: [Jason] where filter that uses a field name? [In reply to] Can't Post

Hi Jason,

Jason asked: Do you want to display all service_categories records? Or just one that has been selected?
studio-a answer: Just the one selected and link with the services titles. Page output display is written below.

PAGE DISPLAY BELOW.
------------------------------------------------------
category_name
summary

service_title
description

service_title
description

service_title
description

<< pagination >>


Jason asked: How are you associating a service_title record with a category?
studio-a answer: We are associating the service titles with the service categories via the drop down list referencing another table (see Admin Set Listed Below AND attached jpg).

ADMIN SETUP BELOW.
------------------------------------------------------
table 01 = service_categories
textfield within this table = category_name
textbox within this table = summary

table 02 = service_titles
droplist within this table = category (this is being dynamically populated from table 01 textfield category_name - see attached image for cross table setup)
textfield within this table = service_title
textbox within this table = description

Looking forward to your help.

studio-a

P.S. We have the page working, but the pagination is now causing a problem. See other post at: http://www.interactivetools.com/forum/gforum.cgi?post=81347#81347


(This post was edited by studio-a on Jun 21, 2010, 10:42 AM)
Attachments: form_dynaimc_categories.jpg (294 KB)


Jason
Staff


Jun 21, 2010, 10:49 AM

Post #15 of 19 (1624 views)
Shortcut
Re: [studio-a] where filter that uses a field name? [In reply to] Can't Post

Hi,

Okay, first we need to select the correct category. Since we're sending the categories name, and not the number, in the url, we need to know how our url is being formatted.

For example:
list.test-1.php?category=*CATEGORY NAME*

For this example, we'll assume this is how it's being done.

Step 1, select the correct category:

Code
  list($service_categoriesRecords, $service_categoriesMetaData) = getRecords(array( 
'tableName' => 'service_categories',
'where' => "category_name='".mysql_escape(@$_REQUEST['category'])."'"
));

if($service_categoriesRecords){
$category=$service_categoriesRecords[0];
}
else{
echo "Category Not Found";
exit;
}


Next we need to select the correct service title records based on the category number of the category we selected:


Code
 list($service_titlesRecords, $service_titlesMetaData) = getRecords(array( 
'tableName' => 'service_titles',
'where' => "category=".intval($category['num']),
'perPage' => '10',
));


We now have all of the service_title records associated with that category stored in $service_titlesRecords.

So, we can output the category information like this:


Code
 
<?php echo $category['category_name'];?>
<?php echo $category['summary];?>


And we can output all the service title information like this:


Code
<?php foreach($service_titlesRecords as $service_title): ?> 
<?php echo $service_title['service_title']; ?>
<?php echo $service_title['description'];?>
<?php endforeach ?>


Give this a try and let me know how it works out for you.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/ 


studio-a
User

Jun 24, 2010, 4:50 AM

Post #16 of 19 (1514 views)
Shortcut
Re: [Jason] where filter that uses a field name? [In reply to] Can't Post

Hi Jason,

Thanks so much for your help!

We have implemented the code using within the URL and ONLY the category_name For Example: www.mydomain.com/pages/serviceList.php?category=Cat Name Here

We see the Category Name and its Summary, but the Service Titles and Descriptions are not showing up. We received the standard message (No records were found.) Any idea why? Attached is the serviceListTest.php file. We have commented out various includes in case that was causing complications, but we still do not see the Service Titles and Service Descriptions.

Thanks again for your work and helping us find a solution!

studio-a


(This post was edited by studio-a on Jun 24, 2010, 4:58 AM)
Attachments: serviceListTest.php (3.06 KB)


Jason
Staff


Jun 24, 2010, 8:24 AM

Post #17 of 19 (1501 views)
Shortcut
Re: [studio-a] where filter that uses a field name? [In reply to] Can't Post

Hi,

If you could email you cms login and FTP details to jason@interactivetools.com, I can take a look into this for you.

Please only send this information by email.

thanks.
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/ 


studio-a
User

Jun 24, 2010, 5:26 PM

Post #18 of 19 (1481 views)
Shortcut
Re: [Jason] where filter that uses a field name? [In reply to] Can't Post

Hi Jason,

We sent you the ftp and cms login info you requested, but we understand things get busy. Attached is the serviceListTest.php file we have been testing using the code you recommended. As we mentioned, the Category Name along with its Summary are displayed when using the URL format (listed below) and your suggested code. However, no Service Titles show up?

For Example: www.mydomain.com/pages/serviceListTest.php?category=Cat Name Here

If anyone can help us we appreciate your time.

Thanks,

studio-a


(This post was edited by studio-a on Jun 24, 2010, 5:28 PM)


Jason
Staff


Jun 25, 2010, 8:30 AM

Post #19 of 19 (1469 views)
Shortcut
Re: [studio-a] where filter that uses a field name? [In reply to] Can't Post

Hi,

The problem seemed to be where we were selecting the category record. If i used the URL format that you listed below, it gave me a "Page Not Found" error, probably do to a reWrite in a .htaccess file.

However, if I changed it to this format:
www.mydomain.com/pages/serviceListTest.php?service_categories=Category Name Here

It would work. The only other change was to change the getRecords request to use "@$_REQUEST['service_categories']".

Take a look and confirm that things are working the way you want now.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/