Jump to content

[SOLVED] Display information from the MySQL Database


topflight

Recommended Posts

$mquery is a result resource, not an array. You need to pull a record (as an array) from this resource. eg;

 

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

$query ="SELECT * FROM `news` ORDER BY `date` DESC LIMIT 5";

if ($mquery = mysql_query($query)) {
  if (mysql_num_rows($mquery)) {
?>
  <table width="10" border="1" cellspacing="0" cellpadding="0">
    <tr>
      <th scope="row">Author Name</th>
    </tr>
    <tr>
      <th scope="row">Date</th>
    </tr>
    <tr>
      <th scope="row">Topic</th>
    </tr>
    <tr>
      <th scope="row">Articale</th>
    </tr>
  </table>
<?php
    while ($data = mysql_fetch_assoc($mquery)) {  //this will loop through your row data returned from the db
      echo "<tr bgcolor=#EEEEEE>\n";
      echo "<td>{$data['authorname']}</td>\n";
      echo "<td>{$data['date]'}</td>\n";
      echo "<td>{$data['newstitle']}</td>\n";
      echo "<td>{$data['news']}</td>\n";
      echo "</tr>\n";
    }
  } else {
    echo "No results found";
  }
} else {
  echo mysql_error();
}

?>
</table>

 

I also added better tests of your results.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.