Incuding two different type of information from the same table on one page

2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 15, 2009   (RSS)

Hi,

I’m having an issue were by I want to display a detail page of an item but want to also list other items in the same category from the same table in the database
For example:

I have a page that lists everything with the category of “Invoicing Module” when I click on this record from the list it opens up a details page to give me the full details about this Invoicing Module Bugfix the tricky bit come when I want to list of other programs that are in the same category of “Invoicing Module” in date descending order (the date bit I can do)

I have tried to create a include page and add a query string to the end but that stops the page from working. I think is the easiest way to go but was unable to get the query string to work

I tried various different ways like the example below:

<?php include inc.php?program='echo $releasenotesRecord['module']?>

and

<?php include("inc.php?program="echo $releasenotesRecord['program'] ); ?>

I did manage to get the page to display what I wanted the include to do by doing the following:

<?php $location = " inc.php?program=";
echo $location; echo $releasenotesRecord['program'] ?>

But how do I get this to work as an include? In the past I have normally needed to include or add the extra functions to pull from a different tables and have been able to do that by using WERE commands at the top and adding this code (standard stuff)

require_once " /lib/viewer_functions.php";
list($releasenotesRecords, $releasenotesMetaData) = getRecords(array(
'tableName' => 'releasenotes',
'perPage' => '10',
));

?>
Also I could do with excluding the current record as well from the list if we use an include to query the list of items in the same catagory then it will obviously include the item we are on.

I thought I could exclude this by using the record number but this would also need to be added to the query string at the end of the include.

Hope this is clear I know it’s sometimes hard to grasp what other people are trying to achive, need any more info let me know

Cheers you Guys

Re: [kevindrinkall] Incuding two different type of information from the same table on one page

By Chris - September 15, 2009 - edited: September 15, 2009

Hi kevindrinkall,

While you can't pass information to includes via new query strings, they have access to any variables that have been declared.

For example, if you already have a $releasenotesRecord variable loaded, you could call your include like this:

<?php include "inc.php"; ?>

... then in inc.php, work with the variable:

if (!$releasenotesRecord) { die('inc.php expects $releasenotesRecord to be defined'); }

list($moreReleasenotesRecords,) = getRecords(array(
'tableName' => 'releasenotes',
'perPage' => '10',
'where' => "program = '{$releasenotesRecord['program']}' and num != $releasenotesRecord['num']", // same program but different num (i.e. exclude the current record)
));


You'll want to be careful with your variable names when doing two getRecords() from the same table. It's easy to accidentally overwrite your variables.

I hope this helps, but if you're still having trouble, please post both your files as attachments and I'll have a look.
All the best,
Chris