Multiple Article listing problem
8 posts by 3 authors in: Forums > CMS Builder
Last Post: November 16, 2010 (RSS)
By gadefgaertgqe - November 15, 2010 - edited: November 15, 2010
I am working with articles from different tables which have then been merged together. The articles list fine, but when I try to use the detail page for the article it shows the wrong one, and always shows the same wrong article.
I am using the 'useSeoUrls' function, and what I have noticed is that if I use the standard URL function it works.
For example:
Shows wrong article:
http://test.sachsbikes.co.uk/news-detail.php/Electric-assisted-bikes-arrive-at-Sachs-1000/
Shows correct article:
http://test.sachsbikes.co.uk/news-detail.php?Electric-assisted-bikes-arrive-at-Sachs-1000/
Here is the code I am using:
Article List:
// Now check if account has Dealer News enabled....
if ($dealer_news == "0") {
// load records
list($www_sachs_newsRecords, $www_sachs_newsMetaData) = getRecords(array(
'tableName' => 'www_sachs_news',
'useSeoUrls' => true,
'allowSearch' => '0',
'perPage' => '5',
));
$allRecords = $www_sachs_newsRecords;
$allMetaData = $www_sachs_newsMetaData;
} else {
// load records
list($www_sachs_newsRecords, $www_sachs_newsMetaData) = getRecords(array(
'tableName' => 'www_sachs_news',
'useSeoUrls' => true,
'allowSearch' => '0',
'perPage' => '5',
));
// Tip: $dealer_sachs_newsRecords, $dealer_sachs_newsMetaData are the array names!
list($dealer_sachs_newsRecords, $dealer_sachs_newsMetaData) = getRecords(array(
'tableName' => $final,
'useSeoUrls' => true,
'allowSearch' => '0',
'perPage' => '5',
));
// put all the records in one list
$allRecords = array_merge( $dealer_sachs_newsRecords, $www_sachs_newsRecords );
$allMetaData = array_merge( $dealer_sachs_newsMetaData, $www_sachs_newsMetaData );
// sort them by date
function createdDateCompareFunction($a, $b) { return -strcmp($a['createdDate'], $b['createdDate']); }
usort($allRecords, 'createdDateCompareFunction');
}
Article Detail:
// Now check if account has Dealer News enabled....
if ($dealer_news == "0") {
// load records
list($www_sachs_newsRecords, $www_sachs_newsMetaData) = getRecords(array(
'tableName' => 'www_sachs_news',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$allRecords = $www_sachs_newsRecords;
$allMetaData = $www_sachs_newsMetaData;
$allRecord = @$allRecords[0]; // get first record
} else {
// load records
list($www_sachs_newsRecords, $www_sachs_newsMetaData) = getRecords(array(
'tableName' => 'www_sachs_news',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
// Tip: $dealer_sachs_newsRecords, $dealer_sachs_newsMetaData are the array names!
list($dealer_sachs_newsRecords, $dealer_sachs_newsMetaData) = getRecords(array(
'tableName' => $final,
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
// put all the records in one list
$allRecords = array_merge( $dealer_sachs_newsRecords, $www_sachs_newsRecords );
$allMetaData = array_merge( $dealer_sachs_newsMetaData, $www_sachs_newsMetaData );
$allRecord = $allRecords[0]; // get first record
}
Hope you can help :)
Kind Regards
paul
Re: [8bit Gamer] Multiple Article listing problem
By gadefgaertgqe - November 15, 2010 - edited: November 15, 2010
What is happening is that in every case the 'first' record is shown. If I modify the url to use ? instead of / then the URL works fine...
So the problem above is a global problem rather than an issue specific to the news articles. Something tells me I am poss being a bit stupid with this. Feel free to point it out ;)
Any ideas?
Kind Regards
Paul
Re: [8bit Gamer] Multiple Article listing problem
By Chris - November 15, 2010
Can we take a closer look at your site to try to figure out what's going wrong? Please fill out a [url http://interactivetools.com/support]Second Level Support Request[/url] with your FTP details and a link to this forum thread.
Chris
Re: [chris] Multiple Article listing problem
:)
Re: [8bit Gamer] Multiple Article listing problem
By Jason - November 16, 2010
This problem was caused by a change on your server where they weren't recognizing "/Electric-assisted-bikes-arrive-at-Sachs-1000/" as a variable in the query string. I added the following code to "includes/database-include-news-detail.php" just before the query to select a specific article. What it does to check to see if the server has recognized a query string. If it hasn't, it populates the server's query string variable with everything that comes after "news-detail.php" in the URL.
//check if SEO url's are being used
if(!$_SERVER['QUERY_STRING']){
$_SERVER['QUERY_STRING']=str_replace("/news-detail.php/","",$_SERVER['REQUEST_URI']);
}
If you use a page that uses "?" instead of "/" the script will still work.
Hope this helps
Jason
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] Multiple Article listing problem
I would never have got that. Any idea why this suddenly started to happen?
I checked that the .htaccess files and they have not changed. Poss server upgrade by host?
After that I am at a loss.
Again, thanks for your help.
Paul
Re: [8bit Gamer] Multiple Article listing problem
By Jason - November 16, 2010
There's a php function called pathinfo() which can take a path, like the one being simulated in the url, and turns it into an array. When this was working, you're host must have had this enabled. If it's disabled, then the array cannot get created and the query was just retrieving the first record in your table.
The code I added gets around this problem.
Glad everything is working for you now.
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: [8bit Gamer] Multiple Article listing problem
By gadefgaertgqe - November 16, 2010 - edited: November 16, 2010
....and just noticed you posted ;)
Thanks for the update. Will speak to the ISP :)