Automatically add users name

16 posts by 5 authors in: Forums > CMS Builder
Last Post: November 11, 2009   (RSS)

By Kenny - September 17, 2009

This works great until I use a search box to get to it when no results exists.

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

Hi sagentic,

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;
}

?>

All the best,
Chris

By Kenny - September 17, 2009

EXCELLENT! Works great...

Re: [gkornbluth] Automatically add users name

By Chris - November 11, 2009

Hi Jerry,

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.
All the best,
Chris

Re: [gkornbluth] Automatically add users name

By Dave - November 11, 2009

Hi Jerry,

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
Dave Edis - Senior Developer
interactivetools.com