Jump to content

help with pulling information for a database please


ricky spires

Recommended Posts

hello.

 

please could someone help me with this conundrum  :confused:

 

im trying to pull my content dynamically. im almost there but im stuck with some code.

 

so i have a layout with 3 columns and in each column i have a place holder. ph01, ph02, ph03

 

each page has its own id and depending on what the page id is i what to pull different elements into the 3 placeholders.

 

so for this code in the database i have the following:

 

 

table name: placeholders

pages_id = page id

ph_number = placeholder number

contElements_id = element ids

 

id    pages_id  ph_number      contElements_id

1    1              1                    1, 2, 3                       

2    1              2                    4, 5, 6                 

3    1              3                    7, 8, 9                         

 

 

table name: contelements

name = name of the element

 

id    name 

1    E1

2    E2

3    E3

4    E4

5    E5

6    E6

7    E7

8    E8

9    E9

 

 

SO, page_ID=1 has 3 placeholders and they should show:

ph01 should display = E1, E2, E3

ph02 should display = E4, E5, E6

ph03 should display = E7, E8, E9

 

 

this is the code im trying to put together.

 

on the page im using this include function in the left, center and right columns.

 


$phNo = "1";
echo include_admin_contElements($phNo, $pageID);  

$phNo = "2";
echo include_admin_contElements($phNo, $pageID);  

$phNo = "3";
echo include_admin_contElements($phNo, $pageID);  

 

 

now this is where the problem is.... i think

in the function file i have this but its a mess..

 

function  include_admin_contElements($phNo, $pageID){


$PH = Placeholders::find_all();

	foreach ($PH as $PHs){
	$PHid = $PHs->id;
	$PHpid = $PHs->pages_id;
	$PHce = $PHs->contElelments_id;
	$PHn = $PHs->ph_number;

		if($pageID == $PHpid){

			$CE = Contelements::find_by_PHce($PHce);

			foreach ($CE as $CEs){
			echo $CEid = $CEs->id;
			echo $CEname = $CEs->name;
			}
		}
	}
}

 

 

- so the idea is i get $phNo, $pageID from the page,

- then find all the placeholders in the database

Placeholders::find_all();

- then if the $pageID is the same as the $PHpid in the placeholder database

if($pageID == $PHpid){
get the content elents for that page.

- then i want to get the elements that belong to that page using

Contelements::find_by_PHce($PHce);

 

but that does not work :(

 

                public static function find_by_PHce($PHce=0){
	$sql = "SELECT * FROM ".self::$table_name." WHERE id=".$PHce."";
	$result_array = self::find_by_sql($sql);
	return $result_array;
                }

 

 

anyway... im stuck. this code doesn't even seperate the 3 different placeholders. it needs a more experienced eye..

 

its a mess

 

please help

 

thanks

 

ricky

solved...

 

function  include_admin_contElements($phNo, $pageID){

 

 

 

$pha = Placeholders::find_by_pageID($pageID);

foreach ($pha as $phas){

$PHceA = $phas->contElements_id;

$PHnA = $phas->phNumber;

 

$CEa = Contelements::find_all();

 

foreach ($CEa as $CEas){

$CEidA = $CEas->id;

$CEnameA = $CEas->name;

 

if($PHceA == $CEidA && $PHnA == $phNo)

echo $CEnameA;

}

}

}

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.