Simple? php include?

7 posts by 2 authors in: Forums > CMS Builder
Last Post: May 29, 2008   (RSS)

By Toledoh - May 29, 2008

Hi Guys,

This is my first attempt a CMS builder... it's looking great!

Have a look at http://fabmosphere.com.tmp.anchor.net.au/services_index.php all going fine, however the text in the left side panel is meant to be the text from http://fabmosphere.com.tmp.anchor.net.au/textPage.php?4 not http://fabmosphere.com.tmp.anchor.net.au/textPage.php.

When I use the code <?php include ("textPage.php?4") ?> I get an error such as can be seen http://fabmosphere.com.tmp.anchor.net.au/casestudies_index.php but if I keep it to <?php include ("textPage.php") ?> itworks but its the wrong content...

It's gotta be something simple right?



Cheers,
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Simple? php include?

By Dave - May 29, 2008

Hi Tim,

PHP include() usually works with filepaths not urls. So you can't have the ?query-string on the end or it won't work.

There's a few different ways to do what you want though. One way is just to include the viewer code directly like this with a "where" to tell it which record number to grab:

<?php
list($myRecords, $myMetaData) = getRecords(array(
'tableName' => 'myTableName',
'where' => "num = '4'"
));
$myRecord = @$myRecords[0]; // get first record
?>

<?php echo $myRecord['title']; ?>


Or if you wanted to keep your code really clean you could put that snippet in a different file (don't forget the "require once" line that goes at the top).

You could also create a field called 'category' and then test for that by value instead of the number. That will make the code more readable. So it would load the sidebar text with the category 'about us':

...
'where' => "category = 'about us'"
...


Hope that makes sense. Let me know if you need more details or help! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Simple? php include?

By Toledoh - May 29, 2008

Thanks for the quick reply!

but... sorry - it's just after 2am here... I'm not thinking that fast...

<?php
list($myRecords, $myMetaData) = getRecords(array(
'tableName' => 'cms_text',
'where' => "num = '4'"
));
$myRecord = @$myRecords[0]; // get first record
?>
<?php echo $myRecord['description']; ?>

still get an error... http://fabmosphere.com.tmp.anchor.net.au/casestudies_index.php
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Simple? php include?

By Dave - May 29, 2008

Hi Tim,

Sorry, make sure you have the require_once line in there (or at the top of the page):

<?php

require_once "/your/path/here/lib/viewer_functions.php";


Let me know if that fixed it.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Simple? php include?

By Toledoh - May 29, 2008

Mmmm... I have the code already at the top of the page...

<?php
require_once "/home/fabmos/public_html/cmsAdmin/lib/viewer_functions.php";
$caseOptions = array(); // NOTE: see online documentation for more details on these options
$caseOptions['tableName'] = 'case'; // (REQUIRED) MySQL tablename to list record from. Example: 'article';
$caseOptions['titleField'] = ''; // (optional) MySQL fieldname used in viewer url for search engines. Example: 'title' would display: viewer.php/article_title_here-123
$caseOptions['viewerUrl'] = 'casePage.php'; // (optional) URL of viewer page. Example: '/articles/view.php';
$caseOptions['perPage'] = ''; // (optional) The number of records to display per page. Example: '5'; Defaults to 10.
$caseOptions['orderBy'] = 'name'; // (optional) Fieldnames to sort by. Example: 'field1, field2 DESC, field3';
$caseOptions['pageNum'] = ''; // (optional) Page number of results to display. Example: '1'; Defaults to ?page=# value, or 1 if undefined
$caseOptions['where'] = ''; // (ADVANCED) Additional MySQL WHERE conditions. Example: 'fieldname = "value"'
$caseOptions['useSeoUrls'] = ''; // (ADVANCED) Set this to '1' for search engine friendly urls: view.php/123 instead of view.php?123 (not supported on all web servers)
list($caseRecordList, $caseListDetails) = getListRows($caseOptions);
?>

I placed this here for calling content from another table... is this the issue, that I'm trying to get content from 2 areas onto one page?



Cheers,
Tim
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Simple? php include?

By Dave - May 29, 2008

Glad to hear it's working! :)
Dave Edis - Senior Developer
interactivetools.com