Question

Could anyone help with this please?

I am pulling the results in below from the cms_page_part table. I know for a fact there should be two rows. One where "name" is equal to "body" and the other that exists is "testionial" however my query below only prints the first one. Is it because im fetching the results incorrectly?

<div class="feature-text">
<?php 

$qpp = mysql_query("SELECT * FROM cms_page_part WHERE page_id=$id"); 
$rpp = $qpp->fetch(PDO::FETCH_BOTH);

foreach ($rpp as $row) {
?>
        <div id="col1">
            <p><?php echo $row['name']=='body' ? $row['content_html'] : NULL; ?></p>
        </div>
        <div id="col2">
          <p class="testimonial"><?php echo $row['name']=='sidebar' ? $row['content_html'] : NULL; ?></p>
        </div>
<?php 
}
?>
</div>
Was it helpful?

Solution

With fetch, you are only fetching one row ; which means you have to call fetch several times to get all the rows.

If you want all the rows in one call, you have to use fetchAll.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top