Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\SERVER\www\emusic\includes\class_mysql_johnny.php on line 76
can some 1 help me plz
this is my class_mysql_johnny.php code
<?php
class class_mysql_johnny {
var $host = "";
var $user = "";
var $pass = "";
var $name = "";
function config(){
global $db;
if(!isset($db)){
$this->error("Error database informations, please try again. ");
}
else{
$this->host = $db["host"];
$this->user = $db["user"];
$this->pass = $db["pass"];
$this->name = $db["name"];
}
}
function access(){
$a = @mysql_connect($this->host, $this->user, $this->pass) or $this->error("Could not connect database. ".mysql_error());
@mysql_select_db($this->name, $a) or $this->error("Could not select database. ".mysql_error());
}
function db_connect($sql_host, $sql_user, $sql_password) {
return mysql_connect($sql_host, $sql_user, $sql_password);
}
function db_select_db($sql_db) {
return mysql_select_db($sql_db) || die("Could not connect to SQL db");
}
function query($query) {
global $debug_mode;
$result = mysql_query($query);
return $result;
}
function db_result($result, $offset) {
return mysql_result($result, $offset);
}
function result($query, $row=0, $field) {
$r = @mysql_result($query, $row, $field);
return $r;
}
function db_fetch_row($result) {
return mysql_fetch_row($result);
}
function getRow($query) {
global $db;
$result=$db->query($query);
return mysql_fetch_array($result);
}
function db_fetch_array($result, $flag=MYSQL_ASSOC) {
return mysql_fetch_array($result, $flag);
}
function fetchRow($result, $flag=MYSQL_ASSOC) {
return mysql_fetch_array($result, $flag);
}
function db_free_result($result) {
@mysql_free_result($result);
}
function numRows($result) {
return mysql_num_rows($result);
}
function db_insert_id() {
return mysql_insert_id();
}
function db_affected_rows() {
return mysql_affected_rows();
}
function db_error($mysql_result, $query) {
global $debug_mode, $error_file_size_limit, $error_file_path, $PHP_SELF;
global $config, $login, $REMOTE_ADDR, $current_location;
if ($mysql_result)
return false;
else {
$mysql_error = mysql_errno()." : ".mysql_error();
echo "<B><FONT COLOR=DARKRED>INVALID SQL: </FONT></B>$mysql_error<BR>";
echo "<B><FONT COLOR=DARKRED>SQL QUERY FAILURE:</FONT></B> $query <BR>";
flush();
}
return true;
}
#
# Execute mysql query adn store result into associative array with
# column names as keys...
#
function func_query($query) {
global $db;
$result = false;
if ($p_result = $db->query($query)) {
while($arr = $db->db_fetch_array($p_result))
$result[]=$arr;
$db->db_free_result($p_result);
}
return $result;
}
function getAll($query) {
global $db;
$result = false;
if ($p_result = $db->query($query)) {
while($arr = $db->db_fetch_array($p_result))
$result[]=$arr;
$db->db_free_result($p_result);
}
return $result;
}
#
# Execute mysql query and store result into associative array with
# column names as keys and then return first element of this array
# If array is empty return array().
#
function func_query_first($query) {
global $db;
if ($p_result = $db->query($query)) {
$result = $db->db_fetch_array($p_result);
$db->db_free_result($p_result);
}
return is_array($result)?$result:array();
}
#
# Execute mysql query and store result into associative array with
# column names as keys and then return first cell of first element of this array
# If array is empty return false.
#
function func_query_first_cell($query) {
global $db;
if ($p_result = $db->query($query)) {
$result = $db->db_fetch_row($p_result);
$db->db_free_result($p_result);
}
return is_array($result)?$result[0]:false;
}
#
# Get county by code
#
function func_get_county ($countyid) {
global $db,$sql_tbl;
$county_name = $db->func_query_first_cell("SELECT county FROM $sql_tbl[counties] WHERE countyid='$countyid'");
return ($county_name ? $county_name : $countyid);
}
}
?>
this is my functions.php code
<?php
function check_right()
{
if ( isset($_SESSION["store_login"])&&($_SESSION["store_login"]=="store_logined")&&($_SESSION["control_right"]==4) ) return true;
$msg="You have no permission to access this area";
$page="admin.php";
page_transfer($msg,$page);
return false;
}
function sql_injection($str){
if(!ereg('[\\\'\"<>:;,=&]', $str)){
return $str;
}else{
echo '<script>window.location="index.php";</script>';
}
}
function check_login()
{
if ( isset($_SESSION["login"])&&($_SESSION["login"]=="logined") ) return true;
$msg = "Bạn chưa đăng nhập.";
$page_url = "index.php?do=user&act=login";
page_transfer($msg,$page_url);
return false;
}
function get_user_info()
{
$user = array();
$user["id_visiter"] = isset($_SESSION["id_visiter"]) ? $_SESSION["id_visiter"] : 0;
$user["email_visiter"] = isset($_SESSION["email_visiter"]) ? $_SESSION["email_visiter"] : '';
$user["name_visiter"] = isset($_SESSION["name_visiter"]) ? $_SESSION["name_visiter"] : '';
$user["time_zone"] = isset($_SESSION["time_zone"]) ? $_SESSION["time_zone"] : 7;
return $user;
}
function randomstring($length){
$haystack = '0123456789ABCDEFGHKLMNOPRSTUVYZabcdefghijklmnopqrstuvwyz';
$needle ="";
while(strlen($needle) < $length) {
$needle .= substr($haystack,rand(0,strlen($haystack)),1);
}
return($needle);
}
function check_number($str)
{
if (ereg('^[[:digit:]]+$', $str))
return 1;
else
return 0;
}
function insert_id(){
$this->insert_id = mysql_insert_id();
return $this->insert_id;
}
function plpage($sqlstmt,$page,$set_per_page)
{
global $db,$do,$set_per_page;
if (!$set_per_page) $set_per_page=$set_per_page;
$result = $db->query($sqlstmt);
$rows = $db->numRows($result);
$p=ceil($rows/$set_per_page);
$str='';
if($p<=1) return $str;
if ($p) $str='';//$str = " Page".$page."/".$p." ";
$first = 0; $last=0;
if ($p<10){
$j=1; $k=$p;
}
else {
if($page<10) { $j=1; $k=10; $last=1;$last=1;}
else {
$first=1;
$j=$page-5;
$k= (($page+5)<$p) ? $page+5 : $p;
$last= (($page+5)<$p) ? 1 : 0;
}
}
if (false&&$first){
$query_str = explode("&page=", $_SERVER['QUERY_STRING']);
$str.="<a class=tit href=\"".$_SERVER['SCRIPT_NAME']."?".$query_str[0]."&page=1\"><b>First</b></a> ";
}
if ($page>1){
$pageprev=$page-1;
$query_str = explode("&page=", $_SERVER['QUERY_STRING']);
$str.=" <a class=tit href=\"".$_SERVER['SCRIPT_NAME']."?".$query_str[0]."&page=$pageprev\"><b>Prev</b></a> ";
}
for($i=$j;$i<=$k;$i++){
if ($i==$page)
$str.="<font class=text_2> $i </font>";
else {
$query_str = explode("&page=", $_SERVER['QUERY_STRING']);
$str.=" <a class=tit href=\"".$_SERVER['SCRIPT_NAME']."?".$query_str[0]."&page=$i\"><b>$i</b></a> ";
}
}
if ($page<$p){
$pagenext=$page+1;
$query_str = explode("&page=", $_SERVER['QUERY_STRING']);
$str.=" <a class=tit href=\"".$_SERVER['SCRIPT_NAME']."?".$query_str[0]."&page=$pagenext\"><b>Next</b></a> ";
}
if (false&&$last){
$query_str = explode("&page=", $_SERVER['QUERY_STRING']);
$str.="<a class=tit href=\"".$_SERVER['SCRIPT_NAME']."?".$query_str[0]."&page=$p\"><b>Last</b></a> ";
}
return $str;
}
function sqlmod($sqlstmt,$page,$set_per_page){ //modified sql query danh cho phan trang
global $set_per_page;
$from = ($page-1)*$set_per_page;
return $sqlstmt." LIMIT ".$from." ,".$set_per_page;
}
function halt($msg){
echo "<center><b>ERROR</b></center><br/>";
echo $msg;
die();
}
function page_transfer($msg,$page)
{
$showtext = $msg;
$page_transfer = $page;
include("templates/transfer.tpl");
exit();
}
function page_transfer2($page="index.php")
{
$page_transfer = $page;
include("templates/transfer2.tpl");
exit();
}
function print_rating($mark){
$str='';
for($i=0;$i<round($mark);$i++){
$str.='<img src="images/star.gif">';
}
for($i=0;$i<5-round($mark);$i++){
$str.='<img src="images/star_blank.gif">';
}
return $str;
}
function cut_string($str,$len,$more){
if ($str=="" || $str==NULL) return $str;
if (is_array($str)) return $str;
$str = trim($str);
if (strlen($str) <= $len) return $str;
$str = substr($str,0,$len);
if ($str != "") {
if (!substr_count($str," ")) {
if ($more) $str .= " ...";
return $str;
}
while(strlen($str) && ($str[strlen($str)-1] != " ")) {
$str = substr($str,0,-1);
}
$str = substr($str,0,-1);
if ($more) $str .= " ...";
}
return $str;
}
?>
can some one help me plz