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)

Hi Everyone.

Lets see if I explain my issue with confusing everyone. The user chooses from the top menu, article1 or article2

I have 1 list page (its also the detail page) that displays the results of two date filters. For the 1st filter (article1 < -365 days), it lists the article titles which meet this criteria in the sidebar, and the user chooses which he wants to read.

For the 2nd filter (article2 >-365), it lists the articles on the sidebar and the user gets to select which he wants to read.

Artcile1 works fine, when you choose an article to read, the page display the article and re-displays the sidebar menu with the titles that meet the article1 criteria.

Artcle2 also works fine initially. After choosing the first article to read, the sidebar menu reverts to the 1st criteria results.

At this point I'm baffled and may have made a bit of a mess of the code! The code is attached, and you can view the sandbox at:
http://hybrid.smallvillages.com/~webster/recentNewsArticles.php

Article1 = Recent News Articles
Article2 = News Archives

Confused!

Ragi
--
northernpenguin
Northern Penguin Technologies

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

recentnewsarticles.php 4K

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: [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/