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: [Toledoh] Simple? php include?

By Toledoh - May 29, 2008

Duh - sorry to waste your time. as soon as I submitted the last message I realised the problem... for every table you need to add the "step 1" stuff...

Got it!

Thanks!
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