Want to connect foreach loop and while loop

Hey guys :slight_smile:

So i create a php generated table and am currently trying to implement a rating system. The system works fine, everything is connected nicely in the sql database.
The problem is that my table is using a while statement to display the data

$sql2= "SELECT * FROM banner_clicks ORDER BY ".$order_var." LIMIT ".$_GET['p'].",". $per_page or die ('sql2 not working');
	$query= mysql_query ($sql2) ;
while ( $row = mysql_fetch_assoc ( $query ) ){...}

The rating system which I am using is using a foreach statement to display the data.

<?php foreach($posts as $ratefield) {
										
				print'
				<table><tr>
				<td>'.$objRate->buttonSet($ratefield['id']).' </td>
				<td>'.htmlentities(stripslashes($ratefield['url'])).'</td>
			</tr>';}
			
		print'	</table> ';

Where posts is defind on the top:

$posts = $objRate->getPosts();

And the getPosts(); is defined in another folder.

public function getPosts() {
		if ($this-&gt;objDb == null) {
			$this-&gt;connect();
		}
		$sql = "SELECT *,
				DATE_FORMAT(`date`, '%d/%m/%Y') AS `date_formatted`
				FROM `{$this->_table_1}`
				WHERE `active` = 1
				ORDER BY `date` DESC";
		$statement = $this-&gt;objDb-&gt;query($sql);
		return $statement-&gt;fetchAll(PDO::FETCH_ASSOC);			
	}
	

I tried several things, such a transforming the foreach statement into a while statement and then using the syntax

$array_length = count($posts);
$iteration    = 0;

while([[$row = mysql_fetch_assoc ( $query )] && [$iteration &lt; $arraylength]){..code.}
$ratefield = $posts[$iteration];
    ...
    $iteration++

The while statement using iteration and arraylength worked fine on its own but not when combined.

So my guess is that I have to somehow combine my $sql12 variable with the $sql variable which is used in the getPosts() function?

Thx a lot for your help!

I found a different way to this and have encountered a different kind of question. I will open a different thread because the title is not applicable.