PDA

View Full Version : PHP Nuke style blocks system


/boot/liam
07-01-04, 05:12 AM
Hi all,

For my portal im trying to do a blocks system.

I have a table called blocks and inside there are these fields;
ID
Name
Used - If set to 1 then its being used if 0 then not used
Left - If set to 1 display on left if 0 then dont
Right - If set to 1 display on right if 0 then dont

Then i have a folder called blocks inside there are the block php files.

Im just wondering how i would grab them from a database and then include them where there supposed to be?

My current system is this;

Grabbing from database;
$blockleft=mysql_fetch_assoc(mysql_query("select * from blocks where `used` = '1' and `left` = '1'"));
$blockright=mysql_fetch_assoc(mysql_query("select * from blocks where `used` = '1' and `right` = '1'"));


Displaying;

include("blocks/$blockleft[name].tpl.php");
include("blocks/$blockright[name].tpl.php");


It works but it only includes one, how do i get it to include all of them :confused:

Cheers!

Matt Wade
07-01-04, 05:09 PM
/* here we do the left side */
$result = mysql_query("select * from blocks where `used` = '1' and `left` = '1'");
while($blockleft=mysql_fetch_assoc($result)) {
include("blocks/$blockleft[name].tpl.php");
}


/* later on we do the right side */
$result = mysql_query("select * from blocks where `used` = '1' and `right` = '1'");
while($blockright=mysql_fetch_assoc($result)) {
include("blocks/$blockright[name].tpl.php");
}


I would also recommend added a order_by column to the database table, that way you can store a number in there and add ' ORDER BY order_by' to your query and have them sorted the way you want....