Karlos2394 Posted April 11, 2009 Share Posted April 11, 2009 Hey! Well basically i'm using a free database class <?php /* Nyna's Database Class (Criminal Existence) Link To Actual File. http://criminalexistence.com/ceforums/index.php?topic=18421.msg83533#msg83533 Copyright (C) 2004-2008 Nyna <nyna@nyna.co.uk> All Rights Reserved. */ class CDatabase { function CDatabase($Server, $Username, $Password, $Database) { $this->_link = @mysql_connect($Server, $Username, $Password); if (!is_resource($this->_link)) { echo 'Connection To MySQL Server Failed!'; exit; } if (!@mysql_select_db($Database, $this->_link)) { mysql_close($this->_link); echo 'Failed To Select Database'; exit; } } function AffectedRows() { return $this->_affected; } function ErrorMsg() { return $this->_error; } function ErrorNo() { return $this->_errno; } function &Execute($sql) { $rs = mysql_query($sql, $this->_link); if ($rs === FALSE) { return $this->RaiseError(); } $this->_affected = @mysql_affected_rows($this->_link); return $rs; } function FetchAll($sql) { $rs = &$this->Execute($sql); if (!is_resource($rs)) { return $rs; } $rows = array(); while ($row = mysql_fetch_assoc($rs)) { $rows[] = $row; } mysql_free_result($rs); return $rows; } function FetchOne($sql) { if (is_array($row = $this->FetchRow($sql))) { return array_shift(array_values($row)); } return $row; } function FetchRow($sql) { $rs = &$this->Execute($sql); if (!is_resource($rs)) { return $rs; } if (($rows = mysql_num_rows($rs)) === FALSE) { $row = $this->RaiseError(); } else if (!$rows) { $row = NULL; } else { $row = mysql_fetch_assoc($rs); } mysql_free_result($rs); return $row; } function &RaiseError() { static $false = FALSE; $this->_errno = mysql_errno($this->_link); $this->_error = mysql_error($this->_link); return $false; } } ?> Well I've got this function function get_rank($stat, $mykey) { global $ir, $UserID, $db; $q=$db->Execute("SELECT count(*) FROM userstats us LEFT JOIN users u ON us.UserID=u.UserID WHERE us.$mykey > $stat AND us.UserID != $UserID AND u.user_level != 0"); return mysql_result($q,0,0)+1; // Being Line 87 } What are the problems? Well.. I recieve this error: Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Cursed (Lite)\ImPoRtAnT-StUfF\GFunc.php on line 87 Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 11, 2009 Share Posted April 11, 2009 I think this line... return mysql_result($q,0,0)+1; should be this... return FetchAll($q); Regards, ACE Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 11, 2009 Share Posted April 11, 2009 The posted code would probably work, except the query is failing and returning a FALSE value, which your code must test for before blindly attempting to access the data. Quote Link to comment Share on other sites More sharing options...
Karlos2394 Posted April 11, 2009 Author Share Posted April 11, 2009 Well I got it working in the end, PFMaBiSmAd put me on the right track, I started messing around with it and my final query worked. function get_rank($MyStat, $OStat) { global $db; $Query = $db->Execute(sprintf("SELECT COUNT(*) FROM `userstats` `us` LEFT JOIN `users` `u` ON `us`.`UserID`=`u`.`UserID` WHERE `us`.`%s` > '%d' AND `u`.`UserLevel`<>'0'", $OStat, $MyStat)); return mysql_result($Query, 0, 0) + 1; } Thanks Ace && PFMaBiSmAd Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.