Reply
Warning: mysql_fetch_array Help needed asap please
Old 03-26-2006, 09:01 PM Warning: mysql_fetch_array Help needed asap please
Junior Talker

Posts: 1
Hi, I am new to php, and i mean new, like yesterday. I have installed software on my site and i am getting errors relations to Warning: mysql_fetch_array. There is not a problem with the db i set up, its with the php code as other people who bought the same software i did are having the same problem and we can get no help from the makers. The error that shows most is as follows:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/besthost/public_html/articledirect/includes/func.php on line 612.
There are 3 different types of errors showing up and i will post all 3 in the hope that some of you guys can help me.
If someone knows what may be causing the problem, is it possible that you could post a reply to this with the fixed code in the reply, because saying to me that i need to add an @ or something in some place would really confuse me lol. The codes as follows and thanks in advance for your help ok. I will also post the other 2 errors that are showing as well shortly. Thanks all.
PHP Code:
<?php
function my_magic_quotes($var) {
   foreach (
$var AS $key => $value) {
       if (
is_array($value))
           
$var[$key] = my_magic_quotes($value);
       else
           
$var[$key] = addslashes($value);
    }
   return 
$var;
}

function 
redirect($strUrl) {
    if (!empty(
$strUrl)) {
        
closedb();
        
header("Location:" $strUrl);
        
//echo $strUrl;
        
exit;
    }
}
function 
closedb() {
    global 
$connect;
    
mysql_close($connect);
}

function 
setErr($strErrMsg) {
    
$_SESSION["errorMessage"] = $strErrMsg;
}

function 
getErr($intColspan) {
    if (!empty(
$_SESSION["errorMessage"])) {
        echo(
"<tr><td align=\"center\" colspan=\"" $intColspan ."\" class=\"err\">" $_SESSION["errorMessage"] . "</td></tr>");
        
$_SESSION["errorMessage"] = "";
    }
}

function 
showErr() {
    echo(
$_SESSION["errorMessage"]);
    
$_SESSION["errorMessage"] = "";
}
function 
setusererr($strErrMsg) {
    
$_SESSION["setusererr"] = $strErrMsg;
}
function 
showusererr() {
    echo(
"<br><font color=red size=2><B>".$_SESSION["setusererr"]);
    
$_SESSION["setusererr"] = "";
}
function 
gotoerror($strErrMsg) {
    
setErr($strErrMsg);
    
redirect("error.php");
}

function 
selfx($strComp1$strComp2) {
    if (!
strcasecmp($strComp1$strComp2))
        return(
" selected");
}

function 
chkfx($strChkValue) {
    if (
trim($strChkValue) != "")
        return (
1);
    else
        return (
0);
}

function 
cbfx($strCbValue) {
    if (
trim($strCbValue) == "1")
        echo(
" checked");
    elseif (
trim($strCbValue) == "true")
        echo(
" checked");
    elseif (
trim($strCbValue) == "True")
        echo(
" checked");
}


function 
getfx($key) {
    if (
get_magic_quotes_gpc())
        return 
stripslashes($_GET[$key]);
    else
        return 
$_GET[$key];
}

function 
postfx($key) {
    if (
get_magic_quotes_gpc())
        return 
stripslashes($_POST[$key]);
    else
        return 
$_POST[$key];
}

function 
dbfx($strVal) {
    return 
addslashes(trim($strVal));
}

function 
pdbfx($strVal) {
    if (
get_magic_quotes_gpc())
        return 
trim($_POST[$strVal]);
    else
        return 
addslashes(trim($_POST[$strVal]));
}

function 
gdbfx($strVal) {
    if (
get_magic_quotes_gpc())
        return 
trim($_GET[$strVal]);
    else
        return 
addslashes(trim($_GET[$strVal]));
}


function 
stsfx($strStatusValue) {
    
//echo $strStatusValue;
    //die;
    
if (trim($strStatusValue) == 1)
        echo(
"<img src=\"../images/icons/+.gif\" border=\"0\">");
    elseif (
trim($strStatusValue) == 2)
        echo(
"<img src=\"../images/icons/+.gif\" border=\"0\">");
    else
        echo(
"<img src=\"../images/icons/-.gif\" border=\"0\">");
}
function 
stsfxroot($strStatusValue) {
    
//echo $strStatusValue;
    //die;
    
if (trim($strStatusValue) == 1)
        echo(
"<img src=\"http://www.webmaster-talk.com/images/icons/+.gif\" border=\"0\">");
    elseif (
trim($strStatusValue) == 2)
        echo(
"<img src=\"http://www.webmaster-talk.com/images/icons/+.gif\" border=\"0\">");
    else
        echo(
"<img src=\"http://www.webmaster-talk.com/images/icons/-.gif\" border=\"0\">");
}
function 
stsfx2($strStatusValue) {
    
//echo $strStatusValue;
    //die;
    
if (trim($strStatusValue) == 1)
        echo(
"<img src=\"http://www.webmaster-talk.com/images/icons/+.gif\" border=\"0\">");
    elseif (
trim($strStatusValue) == 2)
        echo(
"<img src=\"http://www.webmaster-talk.com/images/icons/+.gif\" border=\"0\">");
    else
        echo(
"<img src=\"http://www.webmaster-talk.com/images/icons/-.gif\" border=\"0\">");
}
function 
stsfx1($strStatusValue$strTrue) {
    if (
cmpfx($strStatusValue$strTrue))
        echo(
"<img src=\"../images/icons/-.gif\" border=\"0\">");
    else
        echo(
"<img src=\"../images/icons/+.gif\" border=\"0\">");
}

function 
cmpfx($str1$str2) {
    if (!
strcasecmp($str1$str2))
        return (
1);
    else
        return (
0);
}

function 
sendmail($strTo$strFrom$strCC$strBCC$strSubject$strBody$htmlMail) {
    
$strHeaders "";
    
    if (
$htmlMail) {
        
$strHeaders .= "MIME-Version: 1.0\r\n";
        
$strHeaders .= "Content-type: text/html; charset=iso-8859-1\r\n";
    }
    
    if (
strcmp($strTo"") != 0)
        
$strHeaders .= "To: " $strTo "\r\n";
    
    if (
strcmp($strFrom"") != 0)
        
$strHeaders .= "From: " $strFrom "\r\n";
    
    if (
strcmp($strCC"") != 0) {
        
$strHeaders .= "Cc: " $strCC "\r\n";
        if (
strcmp($strTo"") != 0)
            
$strTo .= "," $strCC;
        else
            
$strTo .= $strCC;
    }
    
    if (
strcmp($strBCC"") != 0) {
        
$strHeaders .= "Bcc: " $strBCC "\r\n";
        if (
strcmp($strBcc"") != 0)
            
$strTo .= "," $strBcc;
        else
            
$strTo .= $strBcc;
    }
    
    return @
mail($strTo$strSubject$strBody$strHeaders);
}

function 
clearsql() {
    global 
$_where;
    
$_where "";
}

function 
appsql($strCond) {
    global 
$_where;
    if (!empty(
$strCond) && strcmp($strCond"") != 0) {
        if (!empty(
$_where) && strcmp($_where"") != 0)
            
$_where .= " AND " $strCond;
        else
            
$_where " WHERE " $strCond;
    }
}

function 
getsql() {
    global 
$_where;
    return (
$_where);
}

function 
iff($prmStr$strTrue$strFalse) {
    if (
$prmStr)
        return 
$strTrue;
    else
        return 
$strFalse;
}

function 
cint($str) {
    return (
round($str0));
}

function 
cdbl($str) {
    return (
round($str2));
}


class 
paging {
    var 
$ps;            //Pagesize
    
var $pss;            //Page scroll size
    
    
var $pg;            //Current page
    
var $tr;            //Total rows
    
var $tp;            //Total pages
    
var $rec;            //Start row for limit
    
var $cps;
    
    var 
$sp;            //Start page
    
var $ep;            //End page
    
    
var $tps;            //Total page sets
    
var $pps;            //Previous page set
    
var $nps;            //Next page set
    
    
var $i;                //Counter
    
    
function paging() {
        
$this->pss 5;
        
        if (!empty(
$_GET["ps"]))
            
$this->ps = (int) $_GET["ps"];
        else
            
$this->ps 10;
        
        if (empty(
$this->ps))
            
$this->ps 10;
        
        if (!empty(
$_GET["pg"]))
            
$this->pg = (int) $_GET["pg"];
        else
            
$this->pg 1;
        
        if (empty(
$this->pg))
            
$this->pg 1;
        
        
$this->1;
    }
    
    function 
setpages($sql) {
        
$rs mysql_fetch_row(mysql_query($sql));
        
$this->tr $rs[0];
        
        
//$this->tp = round($this->tr/$this->ps, 0)+1;
        
$this->tp round($this->tr/$this->ps0);
        
        if (
$this->tp 1$this->tp 1;
        
        if (
$this->tr $this->ps)
            if ((
$this->tr%$this->ps) != 0)
                
$this->tp++;
        
//echo $this->tr%$this->ps;
        
if (!empty($this->pg)) {
            if (
$this->pg $this->tp)
                
$this->pg $this->tp;
        }
        else
            
$this->pg 1;
        
        
$this->rec = ($this->pg*$this->ps)-$this->ps;
    }
    
    function 
getlimit() {
        return 
" limit " $this->rec ", " $this->ps;
    }
    function 
showPagingw($url$qs) {
        
$this->cps cint( ($this->pg $this->pss) + .49 );
        
$this->tps = ((cint( ($this->tp $this->pss) + .49 )-1)*$this->pss)+1;
        
$this->sp = (($this->cps-1)*$this->pss)+1;
        
$this->ep $this->sp 5;
        
        if (
$this->ep $this->tp)
            
$this->ep $this->tp;
        
        
$this->pps $this->sp 5;
        
$this->nps $this->sp 5;
        
        echo 
"<span class=\"paging\">";
        
        
//if ($this->pg == 1)
            //echo "&lt;&lt; &lt;";
        //else {
            //if ($this->pps > 0)
            //    echo "<a href=\"" . $url . "?pg=" . ($this->pps+4) . "&" . $qs . "\" class=botlinks>&lt;&lt;</a>";
            //else
            //    echo "&lt;&lt;";
            //echo "&nbsp;<a href=\"" . $url . "?pg=" . ($this->pg-1) . "&" . $qs . "\" //class=botlinks>&lt;</a>";
        //}
        
        
echo " &nbsp; ";
        
//$this->ep=($this->ep;
        
for ($this->i=$this->sp$this->i<=$this->ep$this->i++) {
            if (
$this->== $this->pg)
                echo 
"[" $this->"]";
            else
                echo 
"<a href=\"" $url "?pg=" $this->"&" $qs "\" class=botlinks>" $this->"</a>";
            echo 
"&nbsp;";
        }
        
        echo 
" &nbsp; ";
        
        
//if ($this->pg == $this->tp)
            //echo "&gt; &gt;&gt;";
        //else {
            //echo "<a href=\"" . $url . "?pg=" . ($this->pg+1) . "&" . $qs . "\" class=botlinks>&gt;</a> ";
            //if ($this->nps <= $this->tps)
            //    echo "<a href=\"" . $url . "?pg=" . $this->nps . "&" . $qs . "\" class=botlinks>&gt;&gt;</a>";
            //else
            //    echo "&gt;&gt;";
        //}
    
}
    function 
showPaging($url$qs) {
        
$this->cps cint( ($this->pg $this->pss) + .49 );
        
$this->tps = ((cint( ($this->tp $this->pss) + .49 )-1)*$this->pss)+1;
        
$this->sp = (($this->cps-1)*$this->pss)+1;
        
$this->ep $this->sp 5;
        
        if (
$this->ep $this->tp)
            
$this->ep $this->tp;
        
        
$this->pps $this->sp 5;
        
$this->nps $this->sp 5;
        
        if (
$this->pg !=&& $this->pg!='' )
            echo  
"<a href='".$url."?pg=".($this->pg-1).$qs."'></a>";
        
//echo "Page:  ";
        
        
if ($this->pg == 1)
            echo 
"&lt;&lt; &lt;";
        else {
            if (
$this->pps 0)
                echo 
"<a href=\"" $url "?pg=" . ($this->pps+4) . "&" $qs "\" class=bodylinks>&lt;&lt;</a>";
            else
                echo 
"&lt;&lt;";
            echo 
"&nbsp;<a href=\"" $url "?pg=" . ($this->pg-1) . "&" $qs "\" class=bodylinks>&lt;</a>";
        }
        
        
        echo 
" &nbsp; ";
            
        for (
$this->i=$this->sp$this->i<=$this->ep$this->i++) {
            
//$url="Listing".$this->i.".html";
            
$url1=$url."?pg=".$this->i.$qs;
            if (
$this->== $this->pg)
            {
                echo 
"[" $this->"]";
                
$nextpage$url."?pg=".($this->i+1).$qs;
                
//echo $nextpage;
            
}
            else
                
                echo 
"<a href=\"" $url1  "\" class=bodylinks><strong>" $this->"</strong></a>";
            echo 
"&nbsp;";
            
$url1='';
        }
            
        
        echo 
" &nbsp; ";
        if (
$this->pg == $this->tp)
            echo 
"&gt; &gt;&gt;";
        else {
            echo 
"<a href=\"" $url "?pg=" . ($this->pg+1) . "&" $qs "\" class=bodylinks>&gt;</a>" ;
            if (
$this->nps <= $this->tps)
                echo 
"<a href=\"" $url "?pg=" $this->nps "&" $qs "\" class=bodylinks>&gt;&gt;</a>";
            else
                echo 
"&gt;&gt;";
        }
        
    }
}

function 
alert($str) {
    echo 
"<script language=\"javascript\" type=\"text/javascript\">" chr(13);
    echo 
"    alert(\"" $str "\");" chr(13);
    echo 
"</script>";
}


function 
getqs($nm) {
    
$strqs "";
    foreach (
$_GET as $key=>$val) {
        if (!
strpos("," $nm ","$key))
            if (
$strqs == "") {
                if (
is_array($val))
                    
$strqs $key "[]=" implode("&" $key "[]="$val);
                else
                    
$strqs $key "=" $val;
            }
            else {
                if (
is_array($val))
                    
$strqs .= "&" $key "[]=" implode("&" $key "[]="$val);
                else
                    
$strqs .= "&" $key "=" $val;
            }
    }
    return 
$strqs;
}
function 
datediff($interval$datefrom$dateto$using_timestamps false) {
  
/*
    $interval can be:
    yyyy - Number of full years
    q - Number of full quarters
    m - Number of full months
    y - Difference between day numbers
      (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
    d - Number of full days
    w - Number of full weekdays
    ww - Number of full weeks
    h - Number of full hours
    n - Number of full minutes
    s - Number of full seconds (default)
  */
  
  
if (!$using_timestamps) {
    
$datefrom strtotime($datefrom0);
    
$dateto strtotime($dateto0);
  }
  
$difference $dateto $datefrom// Difference in seconds
   
  
switch($interval) {
   
    case 
'yyyy'// Number of full years

      
$years_difference floor($difference 31536000);
      if (
mktime(date("H"$datefrom), date("i"$datefrom), date("s"$datefrom), date("n"$datefrom), date("j"$datefrom), date("Y"$datefrom)+$years_difference) > $dateto) {
        
$years_difference--;
      }
      if (
mktime(date("H"$dateto), date("i"$dateto), date("s"$dateto), date("n"$dateto), date("j"$dateto), date("Y"$dateto)-($years_difference+1)) > $datefrom) {
        
$years_difference++;
      }
      
$datediff $years_difference;
      break;

    case 
"q"// Number of full quarters

      
$quarters_difference floor($difference 8035200);
      while (
mktime(date("H"$datefrom), date("i"$datefrom), date("s"$datefrom), date("n"$datefrom)+($quarters_difference*3), date("j"$dateto), date("Y"$datefrom)) < $dateto) {
        
$months_difference++;
      }
      
$quarters_difference--;
      
$datediff $quarters_difference;
      break;

    case 
"m"// Number of full months

      
$months_difference floor($difference 2678400);
      while (
mktime(date("H"$datefrom), date("i"$datefrom), date("s"$datefrom), date("n"$datefrom)+($months_difference), date("j"$dateto), date("Y"$datefrom)) < $dateto) {
        
$months_difference++;
      }
      
$months_difference--;
      
$datediff $months_difference;
      break;

    case 
'y'// Difference between day numbers

      
$datediff date("z"$dateto) - date("z"$datefrom);
      break;

    case 
"d"// Number of full days

      
$datediff floor($difference 86400);
      break;

    case 
"w"// Number of full weekdays

      
$days_difference floor($difference 86400);
      
$weeks_difference floor($days_difference 7); // Complete weeks
      
$first_day date("w"$datefrom);
      
$days_remainder floor($days_difference 7);
      
$odd_days $first_day $days_remainder// Do we have a Saturday or Sunday in the remainder?
      
if ($odd_days 7) { // Sunday
        
$days_remainder--;
      }
      if (
$odd_days 6) { // Saturday
        
$days_remainder--;
      }
      
$datediff = ($weeks_difference 5