how can I create a filter using <?php echo $record['createdBy.fullname'];?>

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

By claire - July 15, 2014

Hi Willy

The createdBy.fullname is a field that's added by the getRecords function. It doesn't appear natively in the table in question, which is why you're getting an error. The field that it references is usually called 'createdByUserNum' and it links to the user's ID number.

There's nothing native to CMSBuilder to do this, unfortunately. There's a few different ways to do it and they'd all be custom. The best way is to use a custom SQL query to get the authors' ID numbers and names, and use that to create the select dropdown - so, something like this:

<?php
$query = "SELECT a.num, a.fullname FROM {$TABLE_PREFIX}accounts a JOIN {$TABLE_PREFIX}bridlington_blogs b ON a.num = b.createdByUserNum";
$accountRecords = mysql_select_query($query);
?>

...

<select name="authorNum">
<?php foreach ($accountRecords as $thisAccount): ?>
<option value = "<?php echo $thisAccount['num'];?>" <?php selectedIf($thisAccount['num'], @$_REQUEST['authorNum']);?>>
<?php echo $thisAccount['fullname']; ?></option>
<?php endforeach ?>
</select>

This is a more complex SQL query than you're used to seeing, but basically what it does is check two tables, accounts and bridlington_blogs, and gives you an array of records (user ID and user name) for user IDs that appear in both. (Here's a W3C schools article for more info on how Joins work: http://www.w3schools.com/sql/sql_join.asp)

You'll likely need to modify your $_REQUEST variable too - I've added authorNum here instead of createdBy.fullname. Let me know if you still have issues with it.

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By willydoit - July 15, 2014

Hi Claire,

I think that what I want to achieve is quite simple and straightforward, given that the answer demands something quite complex it makes me think that I probably arent doing the right things to get what I want in the first place. All I want to do is to have a field within the blogs records which auto populates with the authors name which is contained in the accounts record. You showed me before how to create a drop down list of users taken from a different table but I dont want a list to chose from in this instance, I want the author_ id field to auto populate with the name of the person creating the blog, it would be easy to require the author to input their name manually but that would be a bit amateurish and could result in misspellings which would affect the filters I want to employ.

I do have another question in the forum which preceded this, perhaps a response to that will nullify this issue.

The reason I want to have this information is because I want to be able to provide a drop down list on the viewer page which will allow a viewer to chose from all the contributing authors and be taken to a page which contains all the blogs by that user. It's a pity that you dont have a pre-created template for a multi-user blog facility.

Thanks In advance.

By claire - July 15, 2014

Hi Willy

I think it's probably best if I see the code. Can you email support@interactivetools.com to open a ticket about this and include your cmsAdmin login and FTP details?

Hopefully I'll get a handle on what you want and give you a simpler option.

(I also deleted a few duplicate posts here)

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/