Jump to content

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result


Ugat

Recommended Posts

Hi Guys,

I have a question I got this error in my PHP Program look like this

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/abcom/graphtest.php on line 176

 

Warning: Division by zero in /var/www/abcom/graphtest.php on line 215

 

Warning: Division by zero in /var/www/abcom/graphtest.php on line 215

 

Warning: Division by zero in /var/www/abcom/graphtest.php on line 215

 

Warning: Division by zero in /var/www/abcom/graphtest.php on line 215

 

Warning: Division by zero in /var/www/abcom/graphtest.php on line 215

 

Warning: Division by zero in /var/www/abcom/graphtest.php on line 215

 

 

This the following in my code

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Graph of Prepaid Monitoring</title>
</head>
<body>
<center>
<?php
//ini_set('display_errors',1);
//error_reporting(E_ALL|E_STRICT);
$a         = date('G')-5;
$hr_from_1 = "";
$hr_from_2 = "";
$hr_to_1   = "";
$hr_to_2   = "";
$dt_1      = "";
$dt_2      = "";

if ($a<0) {
$hr_from_1 = 24+date('G')-5;
$hr_to_1   = 23;
$hr_from_2 = 0;
$hr_to_2   = date('G');
$dt_1      = date('n')."/".date('d')-1 ."/".date('Y');
$dt_2      = date('n')."/".date('d')   ."/".date('Y');
$qry_stmt = "
	SELECT TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')) AS x2,
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED) AS xx,
	COUNT(flddate) as td
	FROM tbldigitaltransactionlogs
	WHERE
	RTRIM(SUBSTRING(flddate,1,9)) = '".$dt_1."' AND
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED) BETWEEN ".$hr_from_1." AND ".$hr_to_1."
	GROUP BY
	TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')),
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED)
	ORDER BY
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED)
		union
	SELECT TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')) AS x2,
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED) AS xx,
	COUNT(flddate) as td
	FROM tbldigitaltransactionlogs
	WHERE
	RTRIM(SUBSTRING(flddate,1,9)) = '".$dt_2."' AND
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED) BETWEEN ".$hr_from_2." AND ".$hr_to_2."
	GROUP BY
	TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')),
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED)
	ORDER BY
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED)";

} else {
$hr_from_2 = date('G')-5;
$hr_to_2   = date('G');
$dt_2=date('n')."/".date('d')   ."/".date('Y');
$qry_stmt = "
	SELECT TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')) AS x2,
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED) AS xx,
	COUNT(flddate) as td
	FROM tbldigitaltransactionlogs
	WHERE
	RTRIM(SUBSTRING(flddate,1,9)) '".$dt_2."' AND
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED) BETWEEN ".$hr_from_2." AND ".$hr_to_2."
	GROUP BY
	TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')),
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED)
	ORDER BY
	CAST(	CASE
		 CONCAT(REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':',''),TRIM(REPLACE(SUBSTRING(flddate,LENGTH(flddate)-2,4),':','')))
		 WHEN '12AM' THEN 0
		 WHEN '12PM' THEN 12
		 ELSE
		  REPLACE(SUBSTRING(flddate,LOCATE(' ',flddate)+1,2),':','')+CASE SUBSTRING(flddate,LENGTH(flddate)-1,2) WHEN 'PM' THEN 12 ELSE 0 END
		END
	AS SIGNED)";
}

//echo "qry=".$qry_stmt;
$conn=mysql_connect("172.16.0.45","ssduser","itdev") or die("Could not Connect to the server");
$db=mysql_select_db("abcom",$conn) or die("Could not Connect to the Server");
/*
$query = mysql_query(
"SELECT
trim(replace(substring(flddate,length(flddate)-2,4),':','')) as x2,
replace(substring(flddate,locate(' ',flddate)+1,2),':','')+CASE 'PM' WHEN substring(flddate,length(flddate)-1,2) THEN 12 ELSE 0 END as xx,
count(flddate) as td
FROM tbldigitaltransactionlogs
WHERE rtrim(Substring(fldDate,1,9)) Between '".$date_from."'  And '".$date_to."'
AND replace(substring(flddate,locate(' ',flddate)+1,2),':','')+CASE 'PM' WHEN substring(flddate,length(flddate)-1,2) THEN 12 ELSE 0 END    Between ".$hour_from." And ".$hour_to."
GROUP BY trim(replace(substring(flddate,length(flddate)-2,4),':','')),
trim(replace(substring(flddate,10,3),':',''))
ORDER BY 1 ASC,2 ASC");
*/
$query = mysql_query($qry_stmt);
$test = array($title);
$test2=array($title);
$max_new = 0;
while($r=mysql_fetch_array($qry_stmt))
{
$set = array();
$title=$r[date('n-d-Y')];
array_push($test,$r['td']);
array_push($test2,$r['xx'].'HH');
echo $title;
echo $title2;
if ($max_new >=$r['td']) {
} else {
	$max_new = $r['td'];
}
}
      $selected_year = addslashes($_GET['fldDate']);
$get=addslashes($_GET['fldDigitalID']);
$data = $test2;
        $x_fld = $test;
        $max = $max_new;
        for ($i=0;$i<7;$i++){
        if ($data[$i] > $max)$max=$data[$i];
        }
        $im = imagecreate(800,600);
        $white = imagecolorallocate($im,255,255,255);
        $black = imagecolorallocate($im,0,0,0);
        $red = imagecolorallocate($im,255,0,0);
        $green = imagecolorallocate($im,0,255,0);
        $blue = imagecolorallocate($im,0,0,255);
        imageline($im, 10, 5, 10, 230, $blue );
        imageline($im, 10, 230, 300, 230, $blue );
        imagestring($im,20,200,5,"Prepaid Monitoring System",$black);
        imagestring($im,20,280,240,"Time",$black);
imagestring($im,20,100,50,"",$red);
imagestring($im,20,125,75,"",$green);
        $x = 15;
        $y = 230;
        $x_width = 20;
        $y_ht = 30;
        for ($i=0;$i<7;$i++)
{
          $y_ht = ($data[$i]/$max)* 100;            imagerectangle($im,$x,$y,$x+$x_width,($y-$y_ht),$red);
          imagestring( $im,2,$x-1,$y+1,$x_fld[$i],$black);
          imagestring( $im,2,$x-1,$y+10,$data[$i],$black);
          $x += ($x_width+20);
        }
       imagejpeg( $im, "graph.jpeg", 90);
       imagedestroy($im);
       echo "<img src='graph.jpeg'><p></p>";
?>
</center>
</body>
</html>

Pls help me since yesterday I had headache is there something wrong with my code.

 

Thanks hope you can help me.

 

 

Warning: Division by zero in /var/www/abcom/graphtest.php on line 215

Link to comment
Share on other sites

Okay, that is a lot of code, especially MySQL code to go through.  You have a problem with your query statement which is why you are recieving all of those other errors.  Please put this at the end of your query to find a more 'descriptive' error message:

 

$query = mysql_query($qry_stmt) or die(mysql_error());

 

(moving to the more appropriate "MySQL Help" section)

Link to comment
Share on other sites

Hi Sir Ken2k7.

 

I got this error in my program You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''5/12/2009' AND CAST( CASE CONCAT(REPLACE(SUBSTRING(flddate

 

Can you help me in mysql statement query.

 

Thanks.

Link to comment
Share on other sites

Hi Sir Ken2k7.

 

I got this error in my program You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''5/12/2009' AND CAST( CASE CONCAT(REPLACE(SUBSTRING(flddate

 

Can you help me in mysql statement query.

 

Thanks.

No; I cannot. I have *NO* idea what you're trying to do.

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.