Jump to content

loop question


ricky spires

Recommended Posts

hello

 

im having a little trouble getting what i want back from my loop.

 

on my page i have 2 placeholders. each placeholder needs to pull the element id from the db that belong in that placeholder

 

so in the db i have these columns:

 

id            = (the placeholder id)

number    = (the placeholder number)

element.    = (the element id)

 

for example:

 

place holder 1 has element_id 1 & 2

place holder 2 has element_id 1 & 3

 

id  -  number  -  element_id

 

1  -  1  -  1

2  -  1  -  2

3  -  2  -  1

4  -  2  -  3

 

 

 

in the places holder if have:

 

//place holder 1
$phNo = "1";
$holder = Placeholders::find_by_phID($phNo);

//place holder 2
$phNo = "2";
$holder = Placeholders::find_by_phID($phNo);

 

 

this is the class code: - I MIGHT BE DOING THIS WRONG

public function find_by_phID($phNo=0){

	$sql = "SELECT * FROM ".self::$table_name." WHERE number=".$phNo."";
	$result_array = self::find_by_sql($sql);
	return !empty($result_array) ? array_shift($result_array) : false;
}

 

 

 

THIS IS WHAT I TRIED:

 

inside the placeholder i put a loop:

 

<?php
$phNo = "1";
$holder = Placeholders::find_by_phID($phNo);

foreach ($holder as $holders){
echo "Elements id = ".$holder->contElements_id."<br />";
}
echo "<br/>";
?>

 

 

but the retults are all wrong.

 

it comes back with:

 

Elements id = 5

Elements id = 5

Elements id = 5

Elements id = 5

Elements id = 5

Elements id = 5

Elements id = 5

 

 

what placeholder 1 should come back with is just element id 1 & 2

 

Elements id = 1

Elements id = 2

 

 

 

any thoughts

 

thanks

rick

Link to comment
https://forums.phpfreaks.com/topic/248934-loop-question/
Share on other sites

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.