You are missing our premiere tool bar navigation system! Register and use it for FREE!

NukeCops  
•  Home •  Downloads •  Gallery •  Your Account •  Forums • 
Readme First
- Readme First! -

Read and follow the rules, otherwise your posts will be closed
Modules
· Home
· FAQ
· Buy a Theme
· Advertising
· AvantGo
· Bookmarks
· Columbia
· Community
· Donations
· Downloads
· Feedback
· Forums
· PHP-Nuke HOWTO
· Private Messages
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Theme Gallery
· Top
· Topics
· Your Account
Who's Online
There are currently, 365 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
How to create a block, a practical example

20.2.2. How to create a block, a practical example

We will make a very simple block that shows the pages visited in our site the day before. We'll have a single query and a single value, in order to make things easier. Our block is called "hits", so the complete name of the block will be block-hits.php

First of all, we open the php tag

<?php

Then we insert the protection script we've seen before:

if (eregi("block-hits.php", $PHP_SELF)) {
Header("Location: index.php");
die();
}

And now we insert the variables that we want to call (in this case the parameter $prefix and $dbi, which handles the database abstraction):

global $prefix, $dbi;

Now we continue inserting the query that reads from the database how many pages were seen in our site: (the instruction would be "read the first line value of the table nuke_counter in the cell count")

$result = sql_query("select count from "$prefix."_counter 
                     order by type desc limit 0.1", $dbi);
list($count) = sql_fetch_row($result, $dbi);

Finally, we pass the "$content" variable that will be echoed by the block and close the PHP tag:

$content. = $count
?>

Our complete script will be :

<?php
if (eregi("block-hits,php", $PHP_SELF)) {
  Header("Location: index.php");
  die();
}
global $prefix, $dbi;
$result = sql_query("select count from "$prefix."_counter 
                     order by type desc limit 0.1", $dbi);
list($count) = sql_fetch_row($result, $dbi);
$content. = $count
?>
Powered by TOGETHER TEAM srl ITALY http://www.togetherteam.it - DONDELEO E-COMMERCE http://www.DonDeLeo.com - TUTTISU E-COMMERCE http://www.tuttisu.it
Web site engine's code is Copyright © 2002 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.036 Seconds - 192 pages served in past 5 minutes. Nuke Cops Founded by Paul Laudanski (Zhen-Xjell)
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::