Display Results of Two filters on the Same List Page

14 posts by 3 authors in: Forums > CMS Builder
Last Post: February 10, 2011   (RSS)

Re: [northernpenguin] Display Results of Two filters on the Same List Page

By Jason - January 31, 2011

Hi Ragi,

I'm a little confused as to the issue. I took a look at your page. As I selected articles from the sidebar, I didn't notice any change in the articles in the sidebar. Is that right, or is that the problem?

One thing I noticed in your code that is probably causing confusion is the reuse of variables.

For example, starting on line 20 you have this code:

list($recent_news_articlesRecords, $recent_news_articlesMetaData) = getRecords(array(
'tableName' => 'recent_news_articles',
'loadUploads' => '0',
'where' => 'datediff(publishDate, curdate()) > -365',

));


Then below on line 51 you have this code:

list($recent_news_articlesRecords, $recent_news_articlesMetaData) = getRecords(array(
'tableName' => 'recent_news_articles',
'where' => 'datediff(publishDate, curdate()) > -365',
));


Since they both use the name $recent_news_articlesRecords the second query will overwrite anything that was in the first query. Since the first instance the of variable was never used, the entire first query isn't needed.

A little while later on line 71 you have this:

list($recent_news_articlesRecords, $recent_news_articlesMetaData) = getRecords(array(
'tableName' => 'recent_news_articles',
'where' => whereRecordNumberInUrl(),


Although this is a different query, it still uses the variable name $recent_news_articlesRecords. This will overwrite everything from the second query. This can make it very difficult to figure out what the variable actually stores at any given time. If you require multiple queries, it's a good practice to use different variable names so you can always tell which one you're referencing.

If you could also give some more clarification to the nature of this problem, I can take a closer look.

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] Display Results of Two filters on the Same List Page

Hi Jason: sorry I took so long to answer, but I tried some of your suggestions, but I think I may have made thing way too complex!

I uploaded the latest version of my file. What happens now is that the "News Archives" top menu does not work. No matter what I do, I get the "Latest News Articles" part of the code only.

http://hybrid.smallvillages.com/~webster/index.php

I am stumped!

Ragi
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] Display Results of Two filters on the Same List Page

By Jason - February 3, 2011

Hi Ragi,

The code is looking a lot more readable now, which is good. I think I've found the problem. This line:
<?php if ($top_menuRecords['num']='2'): ?> will always return true. In PHP "=" assigns a value, where "==" checks equality. Try changing those lines to this:

<?php if ($top_menuRecords['num']==2): ?>

Make this change everywhere you're testing the value of a variable. That should take care of this problem for you.

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] Display Results of Two filters on the Same List Page

By northernpenguin - February 3, 2011 - edited: February 3, 2011

Update: I was wrong, its still not generating the appropriate dated files.

Hi Jason: It looks like its actually working, but a new error has been generated:

In the sidebar: "Notice: Undefined index: num in /home/webster/public_html/recentNewsArticles.php on line 55"

In the main content area:

"Notice: Undefined index: num in /home/webster/public_html/recentNewsArticles.php on line 93"
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] Display Results of Two filters on the Same List Page

By Jason - February 4, 2011

Hi,

the issue is that $top_menuRecords is a set of records, not a single record, you we can't access num like this:
$top_menuRecords['num']

The problem we're having is that there is no difference between clicking "Recent News Articles" and "News Archives" so when the script runs, it won't know to do something different.

There are two solutions we can look at. One would just be using two different files, one for recent news records, and one for archives. This is the most straight forward.

The second would be to append something to the end of the url so we can tell which link was clicked. For example:
http://hybrid.smallvillages.com/~webster/recentNewsArticles.php?show=recent

or

http://hybrid.smallvillages.com/~webster/recentNewsArticles.php?show=archive

We can then test these values on the page to decide what we should do:

if(@$_REQUEST['show'] == "recent"){
//show recent records
}



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] Display Results of Two filters on the Same List Page

Hi Jason:

I tried your second solution with the "?show=recent" method.

It works, sort of... here is what happens:

If you choose "Recent News Articles", it displays the correct article titles in the sidebar. However, when you choose an article, it then lists the articles that meet the "< -365" condition.

If you choose "News Archives", it displays the correct article titles in the sidebar. When you select an article, the correct list is re-posted in the sidebar (> -365).

I had tried the 2 file option earlier, with the same results you see above. I tracked it down to the setting of the name of the detail page URL.

Ragi
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] Display Results of Two filters on the Same List Page

By Jason - February 7, 2011

Hi Ragi,

What's happening here is when you're looking at an individual article, you're not putting your show variable in the url, so when the page loads, it doesn't know which list it should show in the side bar. So, for example, you can structure you're url like this:

http://hybrid.smallvillages.com/~webster/recentNewsArticles.php?2010-Webster-a-Resounding-Success----Except-for-the-Smoke-2&show=recent

All we're doing is appending &show=recent to the end of the url. If you're using ['_link'], you can append it like this:

<a href="<?php echo $record['_link'];?>&show=recent"><?php echo $record['title'];?></a>

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] Display Results of Two filters on the Same List Page

Jason: you're a genius! It works great.

Now, just one more question: currently, if you pick "Recent News Articles" or "News Archives", the first article does not show up in the content area unless you select it from the menu at right.

Is there a way of getting it to display the first article where meets the date parameters? I do have
'orderBy' => 'publishDate DESC',
set.

Ragi
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

Re: [northernpenguin] Display Results of Two filters on the Same List Page

By Jason - February 8, 2011

Hi,

So you want to display the first article that meets the search criteria if a specific article wasn't selected. Is that right?

If you could attach the .php file you're working with, I can give you an example of how to do this.

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/