Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Category

 

 


design9
User

Jan 10, 2012, 8:55 AM

Post #1 of 19 (1771 views)
Shortcut
Category Can't Post

Hello,

Hope fully I can explain what I am trying to achieve.

I have a category table called dir_categories where the user puts in the categories (party, day camps, etc.) I also have a category table called dir_programs. This is where the users can enter ALL program types( arts, music, football, tennis, party venues, etc.). I have a multi table called dir_listings where all listings are input. In that table, I have a list field called program_type so the user can select what program types they want associated with the listing.

Under the dir_categories category table, I have a list field called sel_program. Here I am pulling the list from the dir_programs table. So, when the user goes in to create a new category, they can select which program types they want to show up under that category for search. This is where I have an issue when I try to display the chosen list from the category in the search using a dropdown menu on the specific category page. Instead of the dropdown only showing the program types selected for that category, it shows all program types.

I have attached my code below. (lines 550-561).

Thanks!

April
Attachments: testdaytrips.php (39.9 KB)


Jason
Staff / Moderator


Jan 10, 2012, 9:44 AM

Post #2 of 19 (1769 views)
Shortcut
Re: [design9] Category [In reply to] Can't Post

Hi April,

So if I understand correctly, what you want to do is for each dir_categories record returned, if "programtype" is selected, show a drop down with all of the programs that were selected inside that record. Is that right?

If so, you can give this a try:


Code
 <?php foreach ($dir_categoriesRecords as $record): ?>  

<?php if ($record['programtype']): ?>
<?php $selectedPrograms = array_combine($record['sel_program:values'], $record['sel_program:labels']); ?>

<span class="greentext2">Program Type:</span><br />
<span class="bodytext">
<select name="sel_program">
<option value="">Select a Program Type</option>
<?php foreach ($selectedPrograms as $value => $label): ?>
<option value="<?php echo $value;?>"><?php echo $label ?></option>
<?php endforeach ?>

</select>
</span>
<br /><br />
<?php endif ?>

<?php endforeach ?>


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/ 


design9
User

Jan 10, 2012, 12:08 PM

Post #3 of 19 (1759 views)
Shortcut
Re: [Jason] Category [In reply to] Can't Post

Thank Jason!

That is exactly what I needed. The only issue now is I need to set the category for it to filter because it is currently showing a dropdown for all categories (I only have 2 set up in this test...day trips and party).

http://www.charlotteparent.com/directories/testdaytrips.php

How can I fix that?

April


design9
User

Jan 10, 2012, 1:36 PM

Post #4 of 19 (1753 views)
Shortcut
Re: [design9] Category [In reply to] Can't Post

I also just found another issue. When you complete a search, it comes back with an undefined index error for miles using geocoder. Also, my meta (Showing <?php echo $dir_listingsMetaData['pageResultsStart'];?> - <?php echo $dir_listingsMetaData['pageResultsEnd'];?> of <?php echo $dir_listingsMetaData['totalRecords'];?>) is not showing the correct results.

As for the undefined index area, I know it is because for the premium area I use the following: <?php foreach ($premium_listRecords as $record): ?> where I use<?php foreach ($dir_listingsRecords as $record): ?> for the regular listings and in the geocoder coding at the top of page. So, I know I have the code correct for regular listings as those work. I just don't know how to include the <?php foreach ($premium_listRecords as $record): ?> into the geocoder coding to not give the mile error under premium listings.

You can see what I am talking about by going to this page: http://www.charlotteparent.com/directories/search/searchdaytrips.php

Then perform the following search: birthday in keyword and use 28203 in zip and search within 25 miles. You can then see both issues above.

thanks!
April


Jason
Staff / Moderator


Jan 11, 2012, 11:44 AM

Post #5 of 19 (1711 views)
Shortcut
Re: [design9] Category [In reply to] Can't Post

Hi,

It seems to only produce the error on the premium listings section. Are these being retrieved separately? If you are not using the geocoding options to selected those listings, you won't have access tot he _distance field.

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/ 


design9
User

Jan 11, 2012, 12:01 PM

Post #6 of 19 (1708 views)
Shortcut
Re: [Jason] Category [In reply to] Can't Post

1. Yes, those are being pulled separately. One premium section uses the following:

$wherepre = "pre_listing = '1' AND category LIKE '%\tDay Trips\t%'"; if (@$_REQUEST['alpha']) {

$wherepre .= " AND title LIKE '".mysql_escape(@$_REQUEST['alpha'])."%'";

}

list($premium_listRecords, $premium_listMetaData) = getRecords(array(

'tableName' => 'dir_listings',

'where' => $wherepre,

'perPage' => '25',

'orderBy' => 'title',

));

And the regular listings use:

$where = "pre_listing = '0' AND category LIKE '%\tDay Trips\t%'"; if (@$_REQUEST['alpha']) {

$where .= " AND title LIKE '".mysql_escape(@$_REQUEST['alpha'])."%'";

}

list($dir_listingsRecords, $dir_listingsMetaData) = getRecords(array(

'tableName' => 'dir_listings',

'where' => $where,

'perPage' => '25',

'orderBy' => 'title',

));

So, I was wondering if and how I can update the geocoder section to reflect both sections since both sections are pulling from same table so the premium area will not pull a error on miles.

// get records

$addressRecords = array();

if ($myLat && $myLng) {

$maxDist = floatval(@$_REQUEST['maxDistance']);

list($dir_listingsRecords, $dir_listingsMetaData) = getRecords(array(

'tableName' => 'dir_listings',

'addSelectExpr' => geocoder_getSelectExprForDistance($myLat, $myLng, '_distance', $kmOrMiles), // adds '_distance' field to output records

'where' => geocoder_getWhereForDistanceWithin($myLat, $myLng, $maxDist, $kmOrMiles), // optimization: remove results outside of minimum bounding rectangle

'having' => "_distance <= " . $maxDist, // only show results within max distance

'orderBy' => 'ISNULL(_distance), _distance', // sort nearest records first -and- unknown or undefined distances last

));

}

My other issues are:

2. On the search, the program type is filtering correctly but is showing a dropdown for all categories (I only have 2 set up in this test...day trips and party). On this page, should only show program type dropdown (that has arts, dance etc)



3. When you complete a search, my meta (Showing <?php echo $dir_listingsMetaData['pageResultsStart'];?> - <?php echo $dir_listingsMetaData['pageResultsEnd'];?> of <?php echo $dir_listingsMetaData['totalRecords'];?>) is not showing the correct results.


Jason
Staff / Moderator


Jan 12, 2012, 9:36 AM

Post #7 of 19 (1695 views)
Shortcut
Re: [design9] Category [In reply to] Can't Post

Hi,

1)
You can try this:


Code
list($premium_listRecords, $premium_listMetaData) = getRecords(array( 

'tableName' => 'dir_listings',
'addSelectExpr' => geocoder_getSelectExprForDistance($myLat, $myLng, '_distance', $kmOrMiles), // adds '_distance' field to output records
'where' => $wherepre,
'perPage' => '25',
'orderBy' => 'title',

));


To make this work you need to make sure that the variables $myLat, $myLng and $kmOrMiles are defined before you retrieve the records.

2) How are you determining which categories should be displayed?

3) If you put in this line of code:


Code
<?php showme($dir_listingsMetaData);?>


Could you post what is output?
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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


design9
User

Jan 12, 2012, 10:40 AM

Post #8 of 19 (1693 views)
Shortcut
Re: [Jason] Category [In reply to] Can't Post

2. I am using the following code to pull in the listings based on the category but wasn't sure how to get this to work for program type in search.


Code
 $where = "pre_listing = '0' AND category LIKE '%\tDay Trips\t%'";    
if (@$_REQUEST['alpha']) {
$where .= " AND title LIKE '".mysql_escape(@$_REQUEST['alpha'])."%'";
}

list($dir_listingsRecords, $dir_listingsMetaData) = getRecords(array(
'tableName' => 'dir_listings',
'where' => $where,
'perPage' => '25',
'orderBy' => 'title',
));

$wherepre = "pre_listing = '1' AND category LIKE '%\tDay Trips\t%'";
if (@$_REQUEST['alpha']) {
$wherepre .= " AND title LIKE '".mysql_escape(@$_REQUEST['alpha'])."%'";
}
list($premium_listRecords, $premium_listMetaData) = getRecords(array(
'tableName' => 'dir_listings',
'where' => $wherepre,
'perPage' => '25',
'orderBy' => 'title',

));


The category on this specific page is day trips. I know I need to add something so it pulls the program types for just this category but that is where I got stuck. I have attached page again if you need to see all coding.

3. Here is the output:

Code
Array 
(
[invalidPageNum] =>
[noRecordsFound] => 1
[page] => 1
[perPage] =>
[fromCache] => 0
[totalPages] => 1
[totalRecords] => 0
[pageResultsStart] => 0
[pageResultsEnd] => 0
[prevPage] =>
[nextPage] =>
[prevPageLink] => /directories/search/searchdaytrips.php?title%2Ccategory%2Caddress%2Ccity%2Cstate%2Czipcode%2Cphone%2Csummary%2Cfees%2Cages%2Cgender%2Cprogram_type%2Ccounty_query=birthday&amp;sel_program=&amp;county=&amp;search=1&amp;fromAddress=28203&amp;maxDistance=2&amp;search_x=54&amp;search_y=7&amp;page=
[nextPageLink] => /directories/search/searchdaytrips.php?title%2Ccategory%2Caddress%2Ccity%2Cstate%2Czipcode%2Cphone%2Csummary%2Cfees%2Cages%2Cgender%2Cprogram_type%2Ccounty_query=birthday&amp;sel_program=&amp;county=&amp;search=1&amp;fromAddress=28203&amp;maxDistance=2&amp;search_x=54&amp;search_y=7&amp;page=
[firstPageLink] => /directories/search/searchdaytrips.php
[lastPageLink] => /directories/search/searchdaytrips.php?title%2Ccategory%2Caddress%2Ccity%2Cstate%2Czipcode%2Cphone%2Csummary%2Cfees%2Cages%2Cgender%2Cprogram_type%2Ccounty_query=birthday&amp;sel_program=&amp;county=&amp;search=1&amp;fromAddress=28203&amp;maxDistance=2&amp;search_x=54&amp;search_y=7&amp;page=1
[_detailPage] => http://www.charlotteparent.com/directories/details.php
[_listPage] => http://www.charlotteparent.com/directories/test.php
)


Thanks!
April
Attachments: testdaytrips.php (43.6 KB)


Jason
Staff / Moderator


Jan 13, 2012, 8:30 AM

Post #9 of 19 (1669 views)
Shortcut
Re: [design9] Category [In reply to] Can't Post

Hi April,

What you would need to do is retrieve the current category record that you are using. From there, you can retrieve all the proper program records using the sel_program field of the current category.

I took a look at the showm() output you posted. That ouptut is for a query that returned no records. To take a look at this issue further, please fill in a 2nd Level Support Request.

Thanks.
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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


design9
User

Jan 13, 2012, 9:26 AM

Post #10 of 19 (1664 views)
Shortcut
Re: [Jason] Category [In reply to] Can't Post

I am still doing something wrong. I still do not have the program types filtered based on category. Can you tell me what code I would use to retrieve the current category record?

Thanks!

April


Jason
Staff / Moderator


Jan 16, 2012, 11:00 AM

Post #11 of 19 (1578 views)
Shortcut
Re: [design9] Category [In reply to] Can't Post

Hi April,

Could you please provide some clarification on how you need programs to be filtered?

In your code, your category seems to be "Day Trips". This is used to return a certain number of directory listings. Are programs connected to categories through directory listings (ie, "get all programs associates with the listings that are associated with Day Trips")?

Let me know and we'll see what we can figure out.
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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


design9
User

Jan 16, 2012, 11:28 AM

Post #12 of 19 (1575 views)
Shortcut
Re: [Jason] Category [In reply to] Can't Post

Hi Jason,
Yes, get all programs associates with the listings that are associated with Day Trips is what I want to do. However, I don't have the category set up within program types section to pull from like I am doing in the other code on page which is pulling the listings based on category. I guess that is where I am getting confused.

For the search area, I only want to pull in the program types that are associated with the day trips category. I currently have the program types being chosen under the category section when users are selecting their category, then they can choose the program types that they want to show up with that category. Let me know if you need anything more specific.

Thanks!
April


Jason
Staff / Moderator


Jan 17, 2012, 10:29 AM

Post #13 of 19 (1546 views)
Shortcut
Re: [design9] Category [In reply to] Can't Post

Hi April,

Here is a code example. I had to make a couple of assumptions in this:
1) program_types in the dir_listings section is a multi-value field.
2) this option value of this field is the num of the dir_programs field.

With those assumptions, what we do is combine the regular and premium listings into one array. We then take the program_types:values pseudo field of each record and combine those into a single array. We use that list to get the program records that match that list.

EXAMPLE:


Code
  $allListings     = array_merge($dir_listingsRecords, $premium_listRecords); 
$allProgramTypes = array();
foreach ($allListings as $listing) {
$allProgramTypes = array_merge($allProgramTypes, $listing['program_type:values']);
}

$whereProgram = "";
if ($allProgramTypes) {
$whereProgram = "num IN (".join(",", $allProgramTypes).")";
}

list($dir_programsRecords, $dir_programsMetaData) = getRecords(array(
'tableName' => 'dir_programs',
'allowSearch' => false,
'where' => $whereProgram
));


Hope this helps get you started
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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


design9
User

Jan 17, 2012, 11:11 AM

Post #14 of 19 (1543 views)
Shortcut
Re: [Jason] Category [In reply to] Can't Post

Jason,

I tested this but get an error on output.

Here is the error I am getting:

Code
MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Party Entertainment,Party Supplies,Party Venues)) ORDER BY globalOrder' at line 3


I have attached my page again in case I did something wrong for you to look at.

Thank you,
april
Attachments: testdaytrips.php (44.1 KB)


Jason
Staff / Moderator


Jan 18, 2012, 9:42 AM

Post #15 of 19 (1520 views)
Shortcut
Re: [design9] Category [In reply to] Can't Post

Hi April,

So it looks like your program_type field was set up using title instead of num, so each element in the list needs to have single quotes around it.

Try this:


Code
   $whereProgram = "";   
if ($allProgramTypes) {

$programTypeString = "";

foreach ($allProgramTypes as $type) {
$programTypeString .= "'$type',";
}

$programTypeString = rtrim($programTypeString, ",");

$whereProgram = "title IN ($programTypeString)";
}

list($dir_programsRecords, $dir_programsMetaData) = getRecords(array(
'tableName' => 'dir_programs',
'allowSearch' => false,
'where' => $whereProgram
));


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/ 


design9
User

Jan 19, 2012, 8:50 AM

Post #16 of 19 (1503 views)
Shortcut
Re: [Jason] Category [In reply to] Can't Post

Hi Jason,

Sorry to keep bothering you with this but it is still not filtering the program types in search based on category. I know I haven't explained my sections and fields well so I am attaching screenshots of those sections so you can see field names, etc.

My three sections:

Directory Listings - Multi record section

Directory Categories - Category section

Directory Program Types - Category section

When I placed the new code, I got an MySQL Error: Unknown column 'title' in 'where clause' because I use name instead of title. However, once I changed title to name in code, I don't get an error but the program types are not filtering based on the category.

Also, In the listings section, program types is a multi value field.

Thanks!

April
Attachments: categories.jpg (398 KB)
  program types.jpg (348 KB)
  directorylistings.jpg (824 KB)


Jason
Staff / Moderator


Jan 19, 2012, 11:25 AM

Post #17 of 19 (1498 views)
Shortcut
Re: [design9] Category [In reply to] Can't Post

Hi April,

If you use debugSql on your query to get programs, what does it output? Also, what is "main_category" in dir_programs have a value of? Does it connect dir_categories to dir_programs? Can we use this to filter?

Let me know.
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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


design9
User

Jan 23, 2012, 9:54 AM

Post #18 of 19 (1415 views)
Shortcut
Re: [Jason] Category [In reply to] Can't Post

When I debugSql I get the following output:


Code
SELECT SQL_CALC_FOUND_ROWS `dir_programs`.* 
FROM `cms_dir_programs` as `dir_programs`
WHERE (name IN ('Multi-Activity','','Party Entertainment','Party Supplies','Party Venues'))
ORDER BY globalOrder
SELECT SQL_CALC_FOUND_ROWS `accounts`.*
FROM `cms_accounts` as `accounts`
WHERE (`num` IN (1))
ORDER BY fullname, username


This is showing my program types I selected for my party planning category (I only have two categories in the system that have associated listings as a test right now: Party Planning and Day Trips).

Also, the main_category in dir_programs is just the category area where the users put in a list of all their program types. Then when the user goes to the dir_categories section and input theit categories, I have a list field their pulling up all the program types from the dir_programs category section where they can choose what program types they want to show with that category. This is where I am retrieving the selected program types from. The name field in this section is the category name and then under select_program that is where they are using a multi value to select whatever program types they want associated with this category.

Thanks!
April


Jason
Staff / Moderator


Jan 24, 2012, 11:52 AM

Post #19 of 19 (1376 views)
Shortcut
Re: [design9] Category [In reply to] Can't Post

Hi April,

If you could fill out a 2nd Level Support Request I can take a look and see if I can tell what's happening.

Thanks,
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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