Hi there, just a quick one (I think), a little stock on displaying PHP results in a div rather than a table. I seem to be managing to display one of the results ok but the rest are not showing, I want them all to display in their own divs. Please see the code below:

<?php
include ("connectionTest.php");
$product = mysql_query("SELECT pagename,content,metaTitle FROM pages");
         $res = mysql_fetch_array($product);
{
echo '<div class="productPrice">'.$res['pagename'].'<br />
        <span class="bigPrice">'.$res['metaTitle'].' </span><br /></div></a>';
}
?>

Can't work out what's wrong though. Always a great deal of help on this forum so look forward to a reply. Appreciate your time.

Recommended Answers

All 5 Replies

Well Im limited in my knowledge of php, but In order to ehco dynamic query results, I would think you would at least need a loop.

Hi there, thanks for your message. How can I achieve a loop? Apologies, I'm still learning in regards to PHP.

Whats wrong with displaying the query results in a dynamic table? Thats what they're actully used for instead of complete page layouts like alot of ppl use them for.

You can still wrap the table in a div if you want and style it that way.

One thing I noticed is that you have { on line 5 and } on line 8. I don't know if these are supposed to be part of a if statement or something but they should not be there alone. Are you sure that your query is returning anything?

You can check the array that your query is returning with

<pre>
print_r($res);
</pre>

I bet the {} was there because he originally had a dynamic table with a do loop around the query results. When he took the table out, along with the do loop, then thats why he has the curly brackets left and why ony the first query results displays as he said.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.