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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.