I'm trying to display comments on my site from my database. I know that my connection is working, as shown by $test (which displays "Array").
How do I convert the array into usable information? This is my best shot, but it doesn't display anything:
<?php
$connect;
$sql_get_topic_info = "SELECT * FROM wall ORDER BY time ASC";
$res_get_comments_info = mysql_query($sql_get_comments_info);
$num_get_comments_info = mysql_numrows($res_get_comments_info);
$test = mysql_fetch_array(mysql_query($sql_get_topic_info)); //just to make sure the connection is working
echo $test; //displays "Array"
//Runs comment loop
$i=0;
while ($i < $num_get_comments_info) {
$sel_comments_info_time = mysql_result($res_get_comments_info,$i,"time");
$sel_comments_info_message = mysql_result($res_get_comments_info,$i,"message");
$sel_comments_info_company = mysql_result($res_get_comments_info,$i,"company");
echo "<li>Company: $sel_comments_info_company<br/>";
echo "Comment: $sel_comments_info_message <br/>";
echo "$sel_comments_info_time";
echo "</li>";
$i++;
}
?>
Updated script: (from answer below)
$result = mysql_query("SELECT company, message FROM wall");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("company: %s message: %s", $row["company"], $row["message"]);
}
mysql_free_result($result);
which prints:
company: company 1 message: message 1company: company 2 message: message 2company: company 3 message: message 3