Automatically add users name
16 posts by 5 authors in: Forums > CMS Builder
Last Post: November 11, 2009 (RSS)
By Kenny - September 17, 2009
For example, go to http://www.realestatecleburne.com/ and search for house with 1 to 2 bedrooms
I get the following error:
MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) AND accounts.hidden = 0 ORDER BY fullname, username' at line 3
Now try it with 1 to 3 bedrooms and it works like it should.
My top o' page code is:
<?php require_once "/home/strange/public_html/webadmin/lib/viewer_functions.php";
list($metatagsRecords, $metatagsMetaData) = getRecords(array(
'tableName' => 'metatags',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$metatagsRecord = @$metatagsRecords[0]; // get first record
list($residentialRecords, $residentialMetaData) = getRecords(array(
'tableName' => 'residential',
'loadCreatedBy' => true,
));
function collectCreatedByUserNum($record) { return $record['createdByUserNum']; }
$accountNums = array_unique(array_map('collectCreatedByUserNum', $residentialRecords));
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => "num IN (" . join(",", $accountNums) . ")"
));
function collectNum($record) { return $record['num']; }
$accountsRecordsByNum = array_combine(array_map('collectNum', $accountsRecords), $accountsRecords);
foreach ( array_keys($residentialRecords) as $key ) {
$record =& $residentialRecords[$key];
$record['createdByUserNumAccount'] = $accountsRecordsByNum[$record['createdByUserNum']];
}
function maxWords($textOrHtml, $maxWords) {
$text = strip_tags($textOrHtml);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);
return $output;
}
?>
Did I break it?
Kenny
Re: [sagentic] Automatically add users name
By Chris - September 17, 2009
Oops, I didn't account for that case! Try this:
<?php require_once "/home/strange/public_html/webadmin/lib/viewer_functions.php";
list($metatagsRecords, $metatagsMetaData) = getRecords(array(
'tableName' => 'metatags',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$metatagsRecord = @$metatagsRecords[0]; // get first record
list($residentialRecords, $residentialMetaData) = getRecords(array(
'tableName' => 'residential',
'loadCreatedBy' => true,
));
if (!empty($residentialRecords)) {
function collectCreatedByUserNum($record) { return $record['createdByUserNum']; }
$accountNums = array_unique(array_map('collectCreatedByUserNum', $residentialRecords));
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => "num IN (" . join(",", $accountNums) . ")"
));
function collectNum($record) { return $record['num']; }
$accountsRecordsByNum = array_combine(array_map('collectNum', $accountsRecords), $accountsRecords);
foreach ( array_keys($residentialRecords) as $key ) {
$record =& $residentialRecords[$key];
$record['createdByUserNumAccount'] = $accountsRecordsByNum[$record['createdByUserNum']];
}
}
function maxWords($textOrHtml, $maxWords) {
$text = strip_tags($textOrHtml);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);
return $output;
}
?>
Chris
By gkornbluth - November 9, 2009 - edited: November 9, 2009
I just tried to implement the code above and I’m getting strange results.
Near as I can tell, the bottom record in the record list does not show up on the list page, but 2 identical entries show up for the next to last record.
In this example I created a total of 6 records.
Here's the link to the list page:
http://artistsofpalmbeachcounty.org/eblast2.php
As you can see there are 6 records, but the last 2 are duplicates and the real last record (test3) does not show at all.
I have no idea why this is happening, but I’ll bet you do.
Best,
Jerry Kornbluth
Here’s the code at the top of my page. The table is called e_blast.
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
require_once "/mypathto/cmsAdmin/lib/viewer_functions.php";
list($e_blastRecords, $e_blastMetaData) = getRecords(array(
'tableName' => 'e_blast',
));
// collect a list of all createdByUserNum in this record set
function collectCreatedByUserNum($record) { return $record['createdByUserNum']; }
$accountNums = array_unique(array_map('collectCreatedByUserNum', $e_blastRecords));
// fetch only the account records we need
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => "num IN (" . join(",", $accountNums) . ")"
));
// index account records by num
function collectNum($record) { return $record['num']; }
$accountsRecordsByNum = array_combine(array_map('collectNum', $accountsRecords), $accountsRecords);
// add 'createdByUserNumAccount' key to records which links to account record
foreach ( array_keys($e_blastRecords) as $key ) {
$record =& $e_blastRecords[$key];
$record['createdByUserNumAccount'] = $accountsRecordsByNum[$record['createdByUserNum']];
}
?>
and the code that I’m using in the body:
<?php foreach ($e_blastRecords as $record): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a><br/>
Author: <span class="body-text-bold-italic"> <?php echo $record['createdByUserNumAccount']['fullname'] ?></span><br />
<?php echo $record['type'] ?><br/>
<?php echo date("M jS, Y", strtotime($record['date'])) ?><br/>
<hr color="EFEFEF" width="200" align="center"/>
<?php endforeach; ?>
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Automatically add users name
By Chris - November 11, 2009
Good catch! Please try adding the line in red below:
// add 'createdByUserNumAccount' key to records which links to account record
foreach ( array_keys($e_blastRecords) as $key ) {
$record =& $e_blastRecords[$key];
$record['createdByUserNumAccount'] = $accountsRecordsByNum[$record['createdByUserNum']];
unset($record);
}
I hope this helps! Please let me know either way.
Chris
Re: [gkornbluth] Automatically add users name
By Dave - November 11, 2009
I posted a simpler solution to this on another thread. Let me know if that works for you:
http://www.interactivetools.com/forum/gforum.cgi?post=75764#75764
interactivetools.com