Hi,
I'm fairly new to TinyPortal and PHP. I do know my way around SQL tho.
What I'm looking for is some basic guidelines on how to fetch data from the smf tables and present them in blocks or something.
Example:
Adding a block with a link to a php file that will present the results from a select on the members table. When the users press this link - they should be taken to a page that looks much like the main home portal page, only with the memberslist in the centre (ie retain the themes etc automatically)
I would assume that I'd code some php, save it on the "root" of my forum, then add a link to the php using the "Edit Blocks" thing ? Do I have to add a "action" to do something like this ??
I did search around to try and find examples of this. If my search is bad I appologize and ask if someone could paste theyre finds.
Thanks!
Actually, TinyPortal allows you to create PHP Articles through the TPAdmin section.
So all you would really need to do is to code your PHP and save it in a PHP Article, and then you can actually use the Menu Manager to put it in a Menu block on the side.
The article will then load automatically where you are wanting it to load. Once Bloc releases the next version of TP, you will also be able to control other display features as well (such as whether or not the menu blocks appear or if the author or date/time of the article is needed to be displayed, etc...
Hey thanks Rasyr,
but wouldnt the memberslist actually be displayed in the block by doing it that way? I only want to link to the list so that it gets displayed in the main centre part of the page whenever they press the link (with the rest around, like menus, other blocks etc to be retained)
I hope Im making sense here, hehe.
Showing memberlist: perhaps easiest to just go to index.php?action=mlist..it will then be in the middle..add a menuitem with that link.
Ah yes, Thanks Bloc (wow u got time to help!!!??? ;))
I know of that one...the memberlist was more of a example.
To clearify: Lets say I want a php/mysql select statement only showing member-id and email in a separate memberlist...
Can I use "Add php article" perhaps ??
If so...can someone please show me some examples of what is needed to do a simple select from any of the smf tables and display the result ??
Quote from: fenris_w0lf on January 23, 2006, 11:45:58 AM
Hey thanks Rasyr,
but wouldnt the memberslist actually be displayed in the block by doing it that way? I only want to link to the list so that it gets displayed in the main centre part of the page whenever they press the link (with the rest around, like menus, other blocks etc to be retained)
I hope Im making sense here, hehe.
You apparently misunderstood what I was saying...
Follow these Steps:
1) Click on
TPAdmin button
2) Click on
Edit Articles link
3) Click on
Add PHP-article link (in the Blue bar, if using the 1.1 RC1 default theme)
4) Enter your Code (don't forget to give it a title or something)
5) Save
6) Click on
Menu Manager link
7) Click on
Add Menu Item8) Fill in a Name for the article, select Article as the Type, and in the active drop list select the article you just created, and select its position.
9) Save, and then make it active (by clicking on the green circle in the Edit column of the Menu Manager screen).
Then, so long as you have the menubox being displayed in either the left or right column, the link will show up (it is automatically made for you from the stuff you selected in the Manu Manager), and when you click on it, your PHP article will show in the center.
As an example, I recently coded a Simple Image Gallery. This required that I add code to one of the sources files (though I guess I could have done it all in the PHP file), and then I coded the display for it and followed the directions I gave above. This screenshot shows what the result looks like.
You can find the actual thread I started about it here => http://www.tinyportal.net/smf/index.php?topic=2185.0
[attachment deleted by admin]
GREAT!!! Thanks Rasyr!! :D
Could someone please paste some examples
Quote from: fenris_w0lf on January 23, 2006, 12:40:36 PM
...can someone please show me some examples of what is needed to do a simple select from any of the smf tables and display the result ??
I bet theres quite a few of those :)
Read this thread -- http://www.tinyportal.net/smf/index.php?topic=1948.0 -- for the evolution of an example (where I wrote a function that made a call to the DB) to give a listing of the forums in a box on the sidebar).
The principle is the same whether you are writing something to go in a phpbox in the sidebar or into a php article in the middle.
So, I would suggest reading the threads in this forum -- http://www.tinyportal.net/smf/index.php?board=46.0 -- as well as they will give you all sorts of ideas on how to do things.
Great!!!
/me pays Rasyr's next round !!!
:D
well...lol...I'm way to n00b for this :((
I've been messing around trying to get what I wanted;
A php article fetching 4 fields from smf_members ordered by some field I added
but...alas...I get all sorts of errors :((
Could someone pretty please :) help with posting what is mandatory for such a php article ??
I take it you know not to include the php tags? A recent topics SSI call woul look like this in ssi-examples:
<?php ssi_recentTopics(); ?>
But to work in a block/article it should look:
ssi_recentTopics();
In other words, strip out:
<?php
and
?>
what 4 fields are you wanting, and how do you want them displayed?
I'll see if I can come up with something for you...
I've edited the table (eek!) and added a few fields, so lets just call them
memberName, field1, field2, field3
The select itself will prolly be something like:
select memberName, field1, field2, field3 from smf_members where (field1 is not null or field2 is not null or field3 is not null) order by memberName desc
HUGE thanks for helping !!! :)
Okay, I am at work at the moment, but I will see what I can come up with this evening....
Ok, now you have to remember that I am only a noob when it comes to working with PHP (never touched it before beginning of December), and am only vaguely familiar with SQL, so this is quite likely not as optimized as it could be.
Also, to make sure that I had this working good, I used real field names from the members table. You can replace them with the actual field names you are using. You will have to change the names in a number of locations.
Here is the code block:
global $context, $db_prefix;
$request = db_query("SELECT memberName, realName, usertitle, emailAddress, AIM FROM {$db_prefix}members ORDER BY memberName DESC", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
{
while($row = mysql_fetch_assoc($request)){
$context['myCode'][] = array(
'name' => $row['memberName'],
'realName' => $row['realName'],
'title' => $row['usertitle'],
'email' => $row['emailAddress'],
'aim' => $row['AIM'],
);
}
mysql_free_result($request);
}
echo '<table border="1" cellspacing="0" cellpadding="5" align="center">';
echo '<tr bgcolor="#b0c4de"><td><b>Member Name</b></td><td><b>Real Name</b></td><td><b>User Title</b></td><td><b>Email</b></td><td><b>AIM</b></td></tr>';
foreach ($context['myCode'] as $myMember)
{
if ($myMember['realName'] == '' || $myMember['title'] == '' || $myMember['email'] == '' || $myMember['aim'] == '')
$test = false;
else
$test = true;
if($test)
{
echo'<tr><td>'. $myMember['name'] .'</td><td>'. $myMember['realName'] .'</td><td>'. $myMember['title'] .'</td><td>'. $myMember['email'] .'</td><td>'. $myMember['aim'] .'</td></tr>';
}
}
echo '</table>';
You will notice that we started off with the global line. That is there to bring in the global variables that we will be using.
Next is the line that hold the SQL statement. I have no idea how to make it skip those table rows that are blank, so I didn't worry about it there.
After that, I dumped the results into an array.
Most of the SQL call code is cribbed from another function in the forum software, so I didn't reall mess with it.
Once I had my array, I then cycled through ti and formatted my results into a small table. It is here that I checkd for the null field, setting s temp variable to either true or false, and if true, I then output the row into my table.
The following two screenshots show the results. The first is where it is printing all of my results, and the second is the code fully working, stripping out those that I do not want.
[attachment deleted by admin]
[attachment deleted by admin]
That is great work Rasyr. PHP since december? wow.... I wish I was half as fast as you at this.... :uglystupid2:
One question though, can you do this for a member group too?
I'll give it a try either in the morning on tomorrow evening - am too tired this evening to give it a go....
IchBinâââ,¬Å¾Ã,¢:
Yes you can do this for ANY of the tables in the smf database that you have select-right to.
Rasyr:
Awesome !!!! HUGE thanks !! :D
First, if you want to optimize your code a bit instead of:
$request = db_query("SELECT memberName, realName, usertitle, emailAddress, AIM FROM {$db_prefix}members ORDER BY memberName DESC", __FILE__, __LINE__);
try this:
$request = db_query("SELECT memberName, realName, usertitle, emailAddress, AIM FROM {$db_prefix}members where realName != "" and usertitle != "" and emailAddress != "" and AIM != "" ORDER BY memberName DESC", __FILE__, __LINE__);
(note: I havent checked that code on my end so be sure to double-check the result)
This should filter out the ones without any rows that have no values in the columns in question, I get a 0 rows result on this sql because none of my members have any values in the "usertitle" field. Notice that you do not need to test the field MemberName since *all* rows have values there. If you know for a fact that this is true for other of your fileds, then you can also remove those from the where statement. The optimization here is that you only fetch the rows that you're interested in so that the following php code gets less rows to work with, and you can remove the test-section of your php code.
Second; I cant get my article to show on the menu :((
Upon making the article you can decide if its to show on the front-page or not. When I went back and selected that option, the table showed just fine on the front page !!?? (and very nicely so :) ) But for some reason it wont show up in my Main Menu...any ideas ?
I think this might have something to do with the "Edit Blocks" - "Main Menu item" - when I go to edit it; I see this:
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.federationofkings.com%2Ffiles%2Ftemp%2FImage0.jpg&hash=2991d2b5e60c5d3907e5dc1689a8d7334a005059)
(seems I had no Attachement option for the screenshot..... ?)
I had to add that "Chat" action to the action php when I was "fixing" the menu-item for the 3guk PJIRC chat.....does this mean I have to do this for EVERY php article !?
Click on that Menu Manager link. And add the page through there. Then in the Edit Blocks screen, make sure that the default block (that was installed when you installed TP - called Content, IIRC) is turned on. You will see the link in there.
If you deleted that block add in a new one of the type "menubox", and anything you already have in the menu manager will show up.
I am not sure where you got the main menu (as that replicates what is across the top). However, you can add these though the Menu Manager as well. Just select link and put in "index.php?action=xxx" in the third column. The first column being the name you want to show for the link.
Hmm...I have this in my Menu Manager...So I added the article just fine....
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.federationofkings.com%2Ffiles%2Ftemp%2FImage4.jpg&hash=e673402941032988cb394395e5f0bd263c259033)
But it wont show in my Main Menu:
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.federationofkings.com%2Ffiles%2Ftemp%2FImage5.jpg&hash=0291d7726011d3ac8de34c21b3232e5766f0a282)
This also happened when I added the PJIRC Chat. To get that "Chat" link you see on the pic above I had to do as described in my previous post. Add a action to the action php and then add that line in that pic you see in my previous post. That pic is something I find when I press Edit on the "Main Menu" item (pos 0 Left Side Block) on next pic below.
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.federationofkings.com%2Ffiles%2Ftemp%2FImage6.jpg&hash=5245a3428b703b0e63b8005f00d4523a4a2b8f03)
Thats my Edit Blocks menu. I cant seem to find any IIRC here ://
QuoteIf you deleted that block add in a new one of the type "menubox", and anything you already have in the menu manager will show up.
When I try to add a new item these are the types I can choose from:
userbox
newsbox
statsbox
searchbox
html
onlinebox
themebox
shoutbox
catmenu
phpbox
scriptbox
recentbox
ssi
module
rss
???
ahh.. select catmenu (I had the wrong name)
and see what it gives you
Ah yes...soo nice !!! :D
I deleted the Main Menu that was there (it was of type html) and I'm now using a catmenu instead. The (very small) drawback is that one cant seem to get rid of those "bullets" that pops up in front of the items ?
To get rid of the bullets:
Edit TPortalBlocks.template.php, this should be in your default directory. Find the following code:
function TPortal_catmenu()
{
global $context, $settings, $options , $scripturl;
if(isset($context['TPortal']['menu']) && !empty($context['TPortal']['menu'])){
foreach($context['TPortal']['menu'] as $cn){
echo str_repeat(" ", ($cn['sub']+1));
if((!isset($cn['icon']) || (isset($cn['icon']) && $cn['icon']=='')) && $cn['type']!='head' && $cn['type']!='spac'){
echo '<img src="'.$settings['images_url'].'/TPdivider2.gif" alt="" /> ';
}
elseif(isset($cn['icon']) && $cn['icon']!='' && $cn['type']!='head' && $cn['type']!='spac'){
echo '<img alt="*" src="'.$cn['icon'].'" /> ';
}
Change /TPdivider2.gif to /blank.gif and those bullets should disappear. (Note: make sure you have blank.gif in the images folder of the theme you are using -- if not, drop the attached image file into the Themes/[theme you are using]/images folder)
[attachment deleted by admin]
man...is there ANYTHING you dont know how to fix !??
:D
Again Rasyr, HUGE thanks!!!!
Hey! I like tweaking and playing with code. It is how I figure out how it works.. hehe...
Hmm....some of the users reports of:
Warning: mysql_pconnect(): Access denied for user 'xxxxxx_phpbb'@'localhost' (using password: YES) in /home/xxxxxx/public_html/db/aokranks_username.php on line 9
Access denied for user 'xxxxxx_phpbb'@'localhost' (using password: YES)
Any idea ??
Well, it apparently has something to do with the aokranks_username.php page.
I know that isn't a SMF or TP page, so what is it?
What it is ??
Well, I'll tell you what it is!!! :tickedoff:
.
.
...its me jumping the gun with my eyes closed makin miself look like the fool I prolly am...
It was someone clicking the old ranking-list (with a dead database) instead of the new one you helped me make, and I assumed the error was due to the newest one... *blush*
/me <-- :idiot2:
hehe
BTW: Is there a spesific name for the "place" where we've placed the result of that php? You know, in the centre with blocks around and menuline on top...
(My first language is not english prolly one of the reasons I'm asking this)
In the TP Admin area it is called an "Article".
As part of the URL it shows up as index.php?page=x, where x is the article number (in the case of your Ranks page, it is would be index.php?page=7
In general terms, what we did with the rank code is create an html page (all of the other things on the page, the menu, the sidebars, etc. are part of the page template).
Yeah, I prolly didnt phrase my question well enough.
I'll try to explain what I'm asking for in another way. The question is really quite elementary, but usefull for me if I find the right word to use.
If you look at these forums right here, you'll see that its roughly built of major 4 "sections".
1) To the top theres a section with a logo some userinfo, timed logged in etc. 2) To the left there's a section filled with various blocks (such a section can also be placed on the right side - as it is on our TP) 3) At the bottom theres mysql, php links etc. 4) The centre section is right now, when we look at it filled with the forum.
Its the 4th section of the "Home page" (index.php) I want a "general name" for, since the content of it varies depending on where in TP you are (ie when going to the "Home page" its no longer filled with the forum, but could be news etc..)
Having a name for this section would prove useful to me when making posts like the first one in this topic where I wrote:
QuoteExample:
Adding a block with a link to a php file that will present the results from a select on the members table. When the users press this link - they should be taken to a page that looks much like the main home portal page, only with the memberslist in the centre (ie retain the themes etc automatically)
I could simply write:
QuoteExample:
Adding a block with a link to a php file that will present the results from a select on the members table and display it in the xxxxxx
And everyone would know what I was talking about, ie where I wanted the results presented :)
I guess you could call it the "Content Area" or the Body of the page.
The upper section being the Header, the left and right sections being the Sidebars, and the links at the bottom being the Footer.
Great thanks !!
(yet again!) :)
Easier to write this post now:
http://www.tinyportal.net/smf/index.php?topic=2298.0
:D
Are there some functions or classes to use in PHP Articles with the database like Joomla API does?
TinyPortal allows for 2 different types of articles.
The first is normal, html articles.
The second is PHP articles.
IIRC, only the Admin may do PHP Articles,
You can put any php you want in the PHP Articles.
I was talking about what I saw in the article "PHP in articles":
This is a demonstration of a page using PHP for its output - and which is also an "article".It will use classes from SMF natively
I think there is a way to call some functions in SMS. For example: I have to connect to the database to retrieve my own tables. In PHP I would have to write the database password in the code and this is dangerous. I think there is a function of a class (database, perhaps) that let me to do this. What is "classes from SMS natively"?
"classes" meant there are CSS classes used in SMF.
Managing articles means also making php articles - so don't give that option out without trust.
The way to your dilemma is to include() the file with the passwords etc. That way it stays out of the stored code in TP. PHP articles are very basic..if you need custom OOP classes rather include them, and add them directly into the inserted code.
Additionally, if your own tables are part of the same database as SMF/TP, then you won't need to put that information into your code, it is already handled by sections of SMF code.
Look at the various files in the Sources directory to get an idea of how SMF and TP make database calls. You can use that code as your basis for making your own DB calls if you like.