Help with results -resource id#2

 
Post new topic   Reply to topic    Aprelium Forum Index -> Databases
View previous topic :: View next topic  
Author Message
PaulK
-


Joined: 26 Apr 2006
Posts: 132
Location: London, UK

PostPosted: Mon Oct 09, 2006 7:15 pm    Post subject: Help with results -resource id#2 Reply with quote

Hi guys

Can someone take a look at my script and tell me where I have gone wrong?

The script is on two parts, connect to message DB and display last message, then connect to users DB and count who's online.

The script for the message part is displaying Resource ID #2 instead of the last message, yet when I run the query in mysql directly it returns the correct result.

The users online part works perfectly.

Any ideas?

Paul

Code:
<?php
// Connect to the database server
$dbcnx = @mysql_connect('localhost', 'user', 'password');
if (!$dbcnx) {
  exit('<p>Unable to connect to the ' .
      'database server at this time.</p>');
}

// Select the Pro-Lite LED database
if (!@mysql_select_db('prolite')) {
  exit('<p>Unable to locate the message ' .
      'database at this time.</p>');
}
// Request the text of latest message
$message = mysql_query('SELECT message FROM messages order by id desc limit 1')or die("Database SELECT Error<br>".mysql_error());
echo 'Latest message: '.$message;

// Select the nowonline database
if (!@mysql_select_db('nowonline')) {
  exit('<p>Error performing query: ' .
        mysql_error() . '</p>');
}
// Count users online
$online = mysql_query("SELECT DISTINCT ip FROM CJ_UsersOnline") or die("Database SELECT Error<br>".mysql_error());
$user = mysql_num_rows($online);           
echo 'Users online: '.$user;
     
?>
Back to top View user's profile Send private message Visit poster's website
Mikor
-


Joined: 21 Aug 2006
Posts: 144
Location: Hull, England

PostPosted: Mon Oct 09, 2006 8:47 pm    Post subject: Reply with quote

You cant echo a mysql query result like that, use this code:

echo mysql_result([result], [row], [field]);
_________________
Yarrt.com - Free Arcade
RypNet.co.uk - Online Game

MSN:
michael_walker_2004 <at> hotmail <dot> com
Back to top View user's profile Send private message Send e-mail MSN Messenger
PaulK
-


Joined: 26 Apr 2006
Posts: 132
Location: London, UK

PostPosted: Mon Oct 09, 2006 9:15 pm    Post subject: Reply with quote

Thanks for the pointer mike, worked first time!
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Databases All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group