MyBB Community Forums
Variables won't work? - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: Variables won't work? (/thread-176690.html)



Variables won't work? - Sazze - 2015-08-28

Solved.


RE: Variables won't work? - Sazze - 2015-08-30

Still looking for help on this one. If for example enter the variable {$history_date} it won't display anything (yes, i've made it so once a user logins, it will insert the date into the database)

I'm clueless.


RE: Variables won't work? - fizz - 2015-09-02

Can you show me the template you're using?


RE: Variables won't work? - dragonexpert - 2015-09-02

Use usercp_end instead for your hook.


RE: Variables won't work? - Destroy666 - 2015-09-03

Not sure if the hook matters (I think it's fine), but your code is wrong in several other places:
1. You're selecting only the dateline column in the simple_select() query, yet you're trying to use the lastip column. Both need to be selected.
2. $history_date tries to use undefined $loginhistory, which should be $history like in the loop. And why are you using date() instead of MyBB's my_date()?

Also, (int) casting is more preferred than intval(). Your function name is not really unique and may conflict with other plugins.


RE: Variables won't work? - Sazze - 2015-09-03

Solve.d


RE: Variables won't work? - Destroy666 - 2015-09-03

You didn't show the template as someone requested. Can't tell more without it. The loginhistory database structure would help too. Also, where do you insert {$history}? Are you sure it's inserted correctly?

But another mistake I can see is that the loop goes $mybb->settings['showhistory'] times, but the template is called only one time, even if the setting is 0. $history_date gets overwritten several times and the last value is probably used in the template, which is never going to work as supposed to. A template should be concatenated to a variable several times in the loop so that all records will be displayed.


RE: Variables won't work? - Sazze - 2015-09-03

Solved


RE: Variables won't work? - Destroy666 - 2015-09-03

Does the plugin install without any errors? Never heard of smallintval/bigintval column types in any DB system we support.

And the template logic is wrong as I suspected - you can't loop through several records and output them only once in a template. You need to separate this:
<tr>
<td class="trow1">{$history_date}</td>
<td class="trow1">{$history['lastip']}</td>
<td class="trow1">{$userinfo['country_name']}</td>
<td class="trow1">{$userinfo['city']}</td>
</tr>
into another template and then concantenate it to a variable each time. Then output that variable in the main template.


RE: Variables won't work? - Sazze - 2015-09-04

Solved