Membership plugin - author specific photo

Hello all,

I was hoping someone could help me out here. I have added a photo uploader under user accounts so that way, when a user posts something, their image will show up next to their post. I found this code <?php echo $record['createdBy.fullname'] ?> that works perfect for adding the users name that posted the information but I can't seem to get anything to work for images.

I've tried
<?php foreach ($record['avatar'] as $upload): ?>
<?php echo $upload['createdBy.avatar'] ?>
<?php endforeach ?>


But that doesn't work.. No image shows up at all...I've tried...

<?php list(list($current_user_with_uploads),) = getRecords(array('tableName' => 'accounts', 'where' => mysql_escapef('num = ?', $CURRENT_USER['num']), 'allowSearch' => false)); ?>
<?php if (sizeof(@$current_user_with_uploads['avatar'])): $upload = $current_user_with_uploads['avatar'][0] ?>
<img src="<?php echo $upload['urlPath'] ?>" />
<?php else: ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif ?>


Where I get an image (my image) but it shows up for EVERY post. I'm assuming because it is using "current_user" commands and I'm the one signed in. Is there anything I can do to make this work?

Thanks!
Gab

Re: [Gabums85] Membership plugin - author specific photo

Hi Gab,

Don't have a lot of time to work this through right now, but if you’ve added an avatar upload field in the accounts section then it would seem that you could:

1) Use an if statement to match the createdByUserNum on the post with your user account record numbers, and
2) If there’s an avatar image uploaded in that user's account record, show the avatar, if not show your placeholder image.

Just a thought...

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Membership plugin - author specific photo

Hi Jerry,

Thanks for your reply. I've tried to figure out your suggestions but I feel so lost. I've tried this:


<?php foreach ($accountsRecords as $record): ?>
<?php foreach ($record['avatar'] as $upload) {
if (mysql_count('uploads', "tableName = 'accountsRecords' AND fieldName = 'uploads' AND recordNum = '".mysql_escape($record['num'])."'")) {
print '<img src='<?php echo $upload['urlPath'] ?>' width="75" height="75" />';
} else {
print '<img src="images/avatar_fpo.jpg" width="75" height="75" />';
}
?>


But I can't even get the code to be error free. The bolded text always has that red error in Dreamweaver that tells you your not doing something right... Any other thoughts would be greatly appreciated.
Thanks!

Re: [Gabums85] Membership plugin - author specific photo

Hi Gab,

I'm going out for a few hours but when I return I'll take a look.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [Gabums85] Membership plugin - author specific photo

By Jason - January 30, 2012

Hi,

If "avatar" is a field in your accounts table, you can access it through createdBy.avatar. You shouldn't need any extra queries.

For example:

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

<?php foreach ($record['createdBy.avatar'] as $upload): ?>
//output image here.
<?php endforeach ?>

<?php endforeach ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Membership plugin - author specific photo

Hi Jason,

Thank you so much for your reply. I was hoping all I would need is code like that...but I cannot seem to get it to work. When I use this:

<?php foreach ($accountsRecords['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<? php endforeach ?>


I get this error:
Notice: Undefined index: createdBy.avatar in /home/ovation2/public_html/mriintranet/index.php on line 68 Warning: Invalid argument supplied for foreach() in /home/ovation2/public_html/mriintranet/index.php on line 68


When I try this:
<?php foreach ($accountsRecords as $record) :?>
<?php foreach ($record['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php endforeach ?>


I get the same error. Any thoughts?

Re: [Gabums85] Membership plugin - author specific photo

By Jason - January 30, 2012

Hi,

Are accountsRecords coming from the accounts table? If so, you shouldn't need the "createdBy.avatar" field, you should be able to use $record['avatar'].

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Membership plugin - author specific photo

Hmmm... still not working but no error message this time. If I look at the page in firebug it looks like it cannot find the uploaded image. If I do an if statement like so:

<?php foreach ($accountsRecord['avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php if (!$accountsRecord['avatar']): ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif ?>


The fpo image does show up where the uploaded image should...

I'm going to try setting up the image in a different table and see if that makes a difference. I'll let you know what happens. Thank you!

Re: [Gabums85] Membership plugin - author specific photo

So I tried the new table and it still wont work. Every time I try adding 'createdBy', I get the "undefined index" error :(

Re: [Gabums85] Membership plugin - author specific photo

By (Deleted User) - January 30, 2012

Hi Gabums85,

CMSB has a great helper function to show you what the contents of an array are.

If you try
<?php foreach ($accountsRecords as $record) :?>
<?php showme($record); ?>
<?php die(); ?>
<?php foreach ($record['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php endforeach ?>


You should see a detailed output of the array that is $record (and only the first record as we call die() immediately after showing the output).

Check through the keys to that array (the keys are in the square brackets) and see if createdBy.avatar is set at all. If not, try finding the expected data in another field. If you find it, simply swap out the 'createdBy.avatar' key with the new one. If the data is being retrieved at all then the problem lies in the way that accountsRecords is being created.

Hope that helps,

Tom