Jump to content

Problems with mysql_query's, and mysql_fetch_array()


clonetrooper9494
 Share

Recommended Posts

I am making a Chat Room. I have the posting part down, now, I just need help with displaying the posts. It doesn't seem to be doing the While part. I no I didn't misspell the name of the columns, and there are rows in the posts table. The DB.php is the same I use in the post.php page. I don't understand why it isn't echoing the rows!

<?phprequire_once 'db.php';$result = db_query("SELECT * FROM posts WHERE room='test'");  echo "<table border='0'>";    while($row = mysql_fetch_array($result))   {   echo "<tr><td width='75' align='right' valign='top'>".$row['username']."[".$row['date']."]:</td>";   echo "<td width='400' align='left'>".$row['text']."</td></tr>";   }echo "</table><a name='bottom'>"; ?>

Link to comment
Share on other sites

Are you sure the query works? You can also use mysql_num_rows() to check whether it actually selects anything.

Link to comment
Share on other sites

There's nothing wrong with the code, if the information in db.php is correct and if there is data in the database then you will see it printed. Use mysql_error to check for error messages with connecting to the database, but if there was an error there then the later statements would be failing and giving errors. Are error messages enabled?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...