Issue creating page content from two different tables

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 18, 2014   (RSS)

By willydoit - July 16, 2014

Hi all,

I have a detail page from which I have a link designed to load a page called my_blog.php

on the detail page I have created a link using the code below which calls the my_blog.php page and appends the createdByUserNum value on the end

<?php $member1 = $bridlington_blogsRecord['createdByUserNum'] ?>
<a href="my_blog.php?member=<?php echo $member1 ?>">view my other posts </a>

This would produce a url link such as my_blog.php?member=984

The my_blog.php page is designed to pull the authors name, short bio and image from a table called bridlington_bloggers which contains that information for all bloggers in addition to that it needs to display all the blogs that have been created by that blogger, this information is contained within a table called bridlington_blogs which contains all the blogs created by all users.

In my my_blog.php pre head code I have the following which I assumed would open both tables and bring in the records. the lines in red relate to filtering the blog posts for the specific blogger.

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php $member = $_REQUEST['member']; ?>
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/sites/bridlington.net/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records from 'bridlington_blogs'
list($bridlington_blogsRecords, $bridlington_blogsMetaData) = getRecords(array(
'tableName' => 'bridlington_blogs',
'perPage' => '5',
'loadUploads' => true,
'allowSearch' => true,
'orderBy' => 'createdDate DESC',
'where' => 'createdByUserNum = "'. $member .'"' ,
));
// load record from 'bridlington_bloggers'
list($bridlington_bloggersRecords, $bridlington_bloggersMetaData) = getRecords(array(
'tableName' => 'bridlington_bloggers',
'where' => 'createdByUserNum = "'. $member .'"' ,
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$bridlington_bloggersRecord = @$bridlington_bloggersRecords[0]; // get first record
if (!$bridlington_bloggersRecord) { dieWith404("Record not found!"); } // show error message if no record found
?>

My body section at the moment has the following code the red elements show information to be pulled from the table bridlington_bloggers and the green elements show the info pulled from the bridlington_blogs table.

<h1>The Blog of <?php echo htmlencode($record['pen_name']) ?> </h1>
<p><?php echo htmlencode($record['about_me']) ?></p>
<hr>

<?php foreach ($bridlington_blogsRecords as $record): ?>



Title: <?php echo htmlencode($record['title']) ?><br/>
Date: <?php echo date("D, M jS, Y g:i:s a", strtotime($record['date'])) ?><br/><!-- For date formatting codes see: http://www.php.net/date -->
Content: <?php echo $record['content']; ?><br/>
Views: <?php echo htmlencode($record['views']) ?><br/>
Author ID: <?php echo htmlencode($record['author_id']) ?><br/>

<hr/>
<?php endforeach ?>

For some reason when I load the page from the link it properly formats the url and loads the page, it correctly displays the content from the bridlington_blogs table but I get a Undefined variable: record error for the two lines pulling code from the bridlington_bloggers table which are the two lines in red within the h1 and p tags above.

I am unsure as to whether I should use the listing or detail  code for the bridlington_bloggers content and whether this would make any difference, also I dont know if the issue is being caused by using the same variable twice in the pre head code to capture and compare the createdByUserNum, I assume that as the value would be the same each time that it doesn't matter.

Any help or advice anyone can provide to resolve the issue would be appreciated. Please note that I have no mysql or php knowledge so explanations in words of one syllable or by example would be appreciated. 

Thanks in advance for any help provided

By willydoit - July 18, 2014

Hi Claire,

That sorted it thank you.