News:

Wondering if this will always be free?  See why free is better.

Main Menu

How can I show author on display template?

Started by dopeitspaul, July 28, 2014, 04:29:21 PM

Previous topic - Next topic

Arantor

QuoteIf id_member_started doesn't match anything, it should return a null value and the author name would be blank.

Incorrect. The $smcFunc['db_fetch_*'] functions will return false, not null, and trying to take an array key from a non-array value will producing a warning level error through the error handler.

QuoteIt's SIMPLE, and the code I posted is SIMPLE, and does exactly what the OP requested, even if it's not pretty.

So simplicity legitimates bad style and violating multiple rules, awesome. If you tried to package this as a mod and put it on the mod site, it would be refused on all the grounds I gave out.

Being simple is not always best. And just because you think it's simple, now anyone that finds your post will continue to learn bad habits.

There is also no query anywhere in SMF that aliases {db_prefix}messages AS p. {db_prefix}personal_messages AS pm, maybe, but not {db_prefix}messages AS p. There should be no query using variable injection like that anywhere in the code base.

I am sorry to be a hardass because I know you're trying to help but I have see far too many well-meaning but not-so-well thought out or well implemented solutions come along, and I'm doubly annoyed that I even gave you the basis of where to start with it specifically to avoid this sort of thing.

Sir Osis of Liver

Quote from: ahrasis on July 31, 2014, 03:51:09 AM
But you can easily call the topic starter id at the place that you want (i.e. outside while ($message = $context['get_message']())) via $context['topic_starter_id'] but that displays only an id, not the topic starter name.

That's what we were looking for originally, but didn't come up with it.  Still leaves the problem of getting the member's name, which I solved with a simple hack that unleashed a torrent of outrage.

Not unexpectedly -

Quote from: Krash on July 29, 2014, 04:11:27 PM
* Wait til Arantor sees this.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Hj Ahmad Rasyid Hj Ismail

Solved it eh? :P

I'd prefer to play around with this code some more and learn from it.
Quote from: ahrasis on July 31, 2014, 03:51:09 AM
if ($message = $context['get_message']())
{
echo '
', $message['member']['name'], '';
}


Sir Osis of Liver

Quote from: ahrasis on August 01, 2014, 01:01:54 AM
Solved it eh? :P

Yes, I did.  It works fine, except possibly in the "edge cases" Arantor mentioned, which I can probably fix, but won't bother unless OP requests further assistance.  You might notice no one else has posted anything to help this guy.

Quote
I'd prefer to play around with this code some more and learn from it.
Quote from: ahrasis on July 31, 2014, 03:51:09 AM
if ($message = $context['get_message']())
{
echo '
', $message['member']['name'], '';
}



Aside from the fact that the first line is invalid code, you can get it to return member name, but it's name of member who posted first post on that page, so it will be different on different pages.  It's not the topic starter, same problem I had with $context['first_message']. :P
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Hj Ahmad Rasyid Hj Ismail

If it has solved the problem it is good for you and the OP. I didn't test it but the OP said it works.

BTW, I didn't even say mine is a valid code nor solve any problems, but as I took it from SMF code, I will definitely play with it some more and learn from it. I just changed "while" to "if" just to see what it will do. I'd prefer simpler solution, if there is any. ;)

Sir Osis of Liver

The correct way to do it, as was pointed out above, is to query the db for member name in Display.php along with the rest of $topicinfo, but $smcFunc['db_query'] is still a bit over my head, and I can only work with simple queries.  If your MySQL is better than mine, give it a try.

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Advertisement: