This is my code:
<?php
mysql_connect("localhost","*****","********") or die("Can't connect to DB");
mysql_select_db("kroltan_main") or die("Can't select to DB");
$result = mysql_query("SELECT * FROM comments") or die("Can't fetch data");
if(mysql_num_rows($result) > 0){
$info = mysql_fetch_assoc($result);
while($row = mysql_fetch_assoc($result)){
echo "<div class='t_post'>";
echo "<div class='t_message'>" .$row["comment"]. "</div>";
echo "<div class='t_info'>" .$row["name"]. "</div>";
echo "</div>";
}
}
?>
I’m trying to generate a container div with two divs inside, one that shows the “name” value of a MySQL row, and the other that shows the “comment” value. But when i test it, there are no contents (nothing is echoed). My MySQL table has contents on it, so it’s a problem with my code. http://kroltan.eliti.com.br/?/=Talk. The page has some info on it, but that’s irrelevant.
I’ve tidied up the code and the following should work OK:
Changes I’ve made are:
$info = mysql_fetch_assoc()removedecho()calls to make the markup more readableSELECT *