View previous topic :: View next topic |
Author |
Message |
PaulK -
Joined: 26 Apr 2006 Posts: 132 Location: London, UK
|
Posted: Mon Oct 09, 2006 7:15 pm Post subject: Help with results -resource id#2 |
|
|
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 |
|
|
Mikor -
Joined: 21 Aug 2006 Posts: 144 Location: Hull, England
|
Posted: Mon Oct 09, 2006 8:47 pm Post subject: |
|
|
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 |
|
|
PaulK -
Joined: 26 Apr 2006 Posts: 132 Location: London, UK
|
Posted: Mon Oct 09, 2006 9:15 pm Post subject: |
|
|
Thanks for the pointer mike, worked first time! |
|
Back to top |
|
|
|