Jump to content

[SOLVED] Function - Not Working.


Karlos2394

Recommended Posts

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

Link to comment
Share on other sites

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

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.