How to pull details from accounts table

7 posts by 3 authors in: Forums > CMS Builder
Last Post: June 7, 2010   (RSS)

By (Deleted User) - June 4, 2010

Hello,

Each account user has a new field in their account profile for the url of their online web page profile. This field is called profile_url.

I am creating a multi-value list for the latest blog posts. When the person completes the blog they can select from a pulldown list - With following settings:
List
Pulldown
Get options from database
Section Tablename: accounts
Op Values: num
Op labels: fullname

I have also tried to use the beta Lookup Related Fields option as follows:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/yourvita/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."); }
list($site_pagesRecords, $site_pagesMetaData) = getRecords(array(
'tableName' => 'site_pages',
'where' => "num='2'",));
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => whereRecordNumberInUrl(1),
'loadUploads' => '0',
'limit' => '10',
'orderBy' => 'createdDate DESC',));
beta_lookupRelatedFields(array(
'table' => 'blog',
'recordList' => &$blogRecords,
'fieldList' => array( 'name' )));
$blogRecord = @$blogRecords[0];
if (!$blogRecord) {print "Record not found!";exit;}
$errorsAndAlerts = alert(); if (@$CURRENT_USER) {$errorsAndAlerts = "You are already logged in! <a href='{$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL']}'>Click here to continue</a> or <a href='?action=logoff'>Logoff</a>.";}?>


and then the following in the page:

<?php foreach ($blogRecords as $record): ?>
<div class="content_item">
<h3><a href="blog_entry.html"><?php echo $record['title'] ?></a></h3>
<h5><?php if (!$record['name']): ?><?php else: ?>

Added by <?php foreach ($blogRecords as $rec): ?><?php echo $rec['name']; ?><?php endforeach ?>

<?php endif ?> on <?php echo date("jS M Y H:i", strtotime($record['date'])) ?></h5>
<a href="blog_entry.html#comments" class="comments_balloon">21</a>
<p><img src="<?php echo $record['list_image_url_s'] ?>" width="202" height="90" alt="<?php echo $record['list_image_desc_s'] ?>" class="alignleft" /></p>
<p><?php echo $record['list_desc'] ?></p>
<a href="/blogs/<?php echo $record['url_key'] ?>-<?php echo $record['num'] ?>" class="read_more">Continue Reading</a>
</div><?php endforeach; ?>


This is a multi-list so there will be multiple records.

Can Anyone suggest why when I do this it just says Array instead of the persons name in the 'name' record?

Thanks Jono

Re: [jonoc73] How to pull details from accounts table

By Chris - June 4, 2010 - edited: June 4, 2010

Hi Jono,

Since this is a multi-list, there will be multiple records (i.e. an array.) You'll need to iterate over them. Try replacing this:

Added by <?php foreach ($blogRecords as $rec): ?><?php echo $rec['name']; ?><?php endforeach ?>

with this:

Added by <?php foreach ($record['name'] as $account): ?><a href="<?php echo $account['profile_url'] ?>"><?php echo $account['fullname']; ?></a><?php endforeach ?>

Does that help? Please let me know if you have any questions!
All the best,
Chris

Re: [chris] How to pull details from accounts table

By (Deleted User) - June 4, 2010

Hi Chris,

Thanks for trying to help. I change the code to as you described but I am getting a:

Notice: Uninitialized string offset: 0

error however.

J

Re: [jonoc73] How to pull details from accounts table

By Chris - June 4, 2010

Hi J,

Hmm, can you try wrapping that in an IF statement to see if some funky data got in there somehow?

<?php if (is_array($record['name'])): ?>

Added by <?php foreach ($record['name'] as $account): ?><a href="<?php echo $account['profile_url'] ?>"><?php echo $account['fullname']; ?></a><?php endforeach ?>

<?php else: ?>
<?php showme($record['name']) ?>
<?php endif ?>


If something other than an array is in there, this code will spit out what it is. What do you get when you run this?
All the best,
Chris

Re: [chris] How to pull details from accounts table

By (Deleted User) - June 4, 2010

Afraid I am still getting same error.

Funky data is the problem! [;)]

I have added the blog.php page for more info.

J
Attachments:

blogs.php 19K

Re: [Jason] How to pull details from accounts table

By (Deleted User) - June 7, 2010

Jason,

Due to personal info in details requested I have messaged you instead.

Thanks Jono