Category
19 posts by 2 authors in: Forums > CMS Builder
Last Post: January 24, 2012 (RSS)
By design9 - January 10, 2012
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
Re: [design9] Category
By Jason - January 10, 2012
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:
<?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 - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Category
By design9 - January 10, 2012
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
Re: [design9] Category
By design9 - January 10, 2012
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
Re: [design9] Category
By Jason - January 11, 2012
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 - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Category
By design9 - January 11, 2012
$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.
Re: [design9] Category
By Jason - January 12, 2012
1)
You can try this:
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:
<?php showme($dir_listingsMetaData);?>
Could you post what is output?
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Category
By design9 - January 12, 2012
$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:
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&sel_program=&county=&search=1&fromAddress=28203&maxDistance=2&search_x=54&search_y=7&page=
[nextPageLink] => /directories/search/searchdaytrips.php?title%2Ccategory%2Caddress%2Ccity%2Cstate%2Czipcode%2Cphone%2Csummary%2Cfees%2Cages%2Cgender%2Cprogram_type%2Ccounty_query=birthday&sel_program=&county=&search=1&fromAddress=28203&maxDistance=2&search_x=54&search_y=7&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&sel_program=&county=&search=1&fromAddress=28203&maxDistance=2&search_x=54&search_y=7&page=1
[_detailPage] => http://www.charlotteparent.com/directories/details.php
[_listPage] => http://www.charlotteparent.com/directories/test.php
)
Thanks!
April
Re: [design9] Category
By Jason - January 13, 2012
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 [url http://www.interactivetools.com/support]2nd Level Support Request[/url].
Thanks.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Category
By design9 - January 13, 2012
[font "Verdana"]Thanks![/#000000]
[font "Verdana"]April[/#000000]