DISPLAYING THE FIELD ON VIEWUSER.PHP

So now that your users can update their data, now we have to display it.

Open up viewuser.php and examine the contents. Look near the top, do you see the SQL statement that calls everything stored in the fanfiction_authors table? *grin*

 

First of all, the easiest way to display something from the database:

PHP:
  1. $tpl->assign("template variable", $userinfo['database field']);

Here, you're assigning a new template variable field that will display a field from the database in plain text. That's fine if you're calling up something that has probably been written to the database in plain text, such as an unlinked instant messenger screenname.

Example:

PHP:
  1. $tpl->assign("membersince", $userinfo['date']);

That means you can use {membersince} to display the date the person joined your website in your copy of user.tpl.

An extra web site isn't much harder, especially since we've already covered it once before for the stats page. As with the stats page, simply copy everything having to do with the website field, paste, and rename to your fieldname.

 

An instant messenger field looks like this:

PHP:
  1. $tpl->assign("what you want to call it", "<img src=\"images/messenger.gif\" alt=\""._LANGUAGE FILE TAG."\"/> ".($userinfo['field'] ? $userinfo['field'] : _NONE));

What this will do is if they have filled out their contact information, it will return their name. Otherwise, it will simply return the word "None"

Example:

PHP:
  1. $tpl->assign("msn", "<img src=\"images/msntalk.gif\" alt=\""._MSN."\"/> ".($userinfo['MSN'] ? $userinfo['MSN'] : _NONE));

 

A numerical field can be converted to a text answers or even graphics using something like this:

PHP:
  1. if($userinfo['field'] == 0) $tpl->assign("what you want to call it", ""._LANGUAGE FILE TAG."");

Or, for an image:

PHP:
  1. if($userinfo['field'] == 0) $tpl->assign("what you want to call it ", "<img src=\"images/icon.gif\" alt=\""._LANGUAGE FILE TAG."\" title=\""._ LANGUAGE FILE TAG."\"/>");

Simply repeat for as many options as you've offered, changing the 0 to the number you need.

What about linking a user name to a different website? This only works well right now if the person's user name for that site is actually used as a part of the link. There are ways to work around it, but it may take more work.

Example: (My DeviantArt link)

PHP:
  1. $tpl->assign("deviant", <img src=\"images/da.gif\" alt=\""._DA."\"/> $userinfo[DA] ? "<a href=\"http://$userinfo[DA].deviantart.com\" target=\"_blank\" rel=\"nofollow\">$userinfo[DA]</a>" : _NONE);

What this does is pull the person's DeviantArt user name from the database results and inserts it into the link I specified. If there's nothing there, it returns "None."

 

 

And there you've have it! Now all you have to do is insert you template variable into user.tpl and your mod is finished.

You can leave a response, or trackback from your own site.

Leave a Reply