<?php
session_cache_limiter('private,must-revalidate');	
session_start();
	
require_once("config.php");

include ("classes/db_functions.php");
include ("classes/display.php");

$dbf=new db_functions(SM_DB_HOST,SM_DB_USER,SM_DB_PASS,SM_DB_NAME);

?>
<link href="style/report.css" rel="stylesheet" type="text/css" />
<?php

if (@$_POST['Submit']=="Save Report")
{
 $sql = "select * from customreport order by id desc";
 $linkID=mysql_connect(SM_DB_HOST,SM_DB_USER,SM_DB_PASS);
 mysql_select_db(SM_DB_NAME, $linkID);   
 $result = mysql_query($sql)or die(mysql_error()); 
 $nume = mysql_num_rows($result);
 $row=mysql_fetch_array($result);
 
 if (!empty($nume))
    $nume = $row['id'] + 1; 
 else
    $nume=1;
 
 $reportname = $_POST['reportname'];
 $whereclause = addslashes($_POST['whereclause']);
 $choose = addslashes($_POST['choose']);
 $tablename = $_POST['tablename'];
 if (isset($_SESSION['USERID']) and isset($_SESSION['groupid']))
 {   
    $userid = $_SESSION['USERID'];
    $groupid = $_SESSION['groupid'];
 }   
 else
 {   
    $userid = "NAN";
    $groupid = "NAN";
 }   
    
 
 $viewtype = $_POST['viewtype'];
 
 $sql = "INSERT INTO customreport (id,userid,reportname,whereclause,choose,tablename,viewtype,groupid)".
         " VALUES ('$nume','$userid','$reportname','$whereclause','$choose','$tablename','$viewtype','$groupid')";
         
//echo $sql;
$result= mysql_query($sql); 
    
echo "<center>Report Saved !!</center>";    
exit;    
}

$geo = isset($_POST['geo']) ? $_POST['geo'] : "";
$country = isset($_POST['country']) ? $_POST['country'] : "";
$cat = isset($_POST['cat']) ? $_POST['cat'] : "";
$typeofreport = isset($_POST['typeofreport']) ? $_POST['typeofreport'] : "";
$select2= isset($_POST['select2']) ? $_POST['select2'] : "";
$CAM = isset($_POST['CAM']) ? $_POST['CAM'] : "";
$start = isset($_GET['start']) ? $_GET['start'] : "";
$where = isset($_GET['where']) ? $_GET['where'] : "";

if (!empty($select2))
{

for ( $i = 0 ; $i < count($select2) ; $i++ )
{

if ($i==0)
$choose = "`".$select2[$i]."`";
else
$choose = $choose . "," ."`".$select2[$i]."`";
}
  $_SESSION['choose'] = $choose;
}
else
{
    $choose = $_SESSION['choose'];
    $select2 =  explode(",",$_SESSION['choose']);
}

if (empty($where))
{
$whereclause = "";

if ($typeofreport=="tec")
	if ($cat=="1")
	{
		$sCountry = "`venue_asn.Country`";
		$sGEO = "`venue_asn.GEO`";
	}
	else
	{
		$sCountry = "`venue_pep.Country`";
		$sGEO = "`venue_pep.GEO`";
	}
elseif ($typeofreport=="ec")
	{
		$sCountry = "`company.Country`";
		$sGEO = "`company.GEO`";
	}
elseif ($typeofreport=="pc")
	{
		$sCountry = "`company.Country`";
		$sGEO = "`company.GEO`";
		$sCAM = "`company.CAM`";
	}
elseif ($typeofreport=="pu")
	{
		$sCountry = "Country";
	}
elseif ($typeofreport=="ac")
	{
		$sCountry = "Country";
		$sGEO = "geo";
	}
else
	{
	//	echo "stop";
	//	exit;
	}

if (!empty($geo))
    $whereclause = " where $sGEO ='$geo'";

if (!empty($country))
    if(!empty($whereclause))
           $whereclause = $whereclause." and $sCountry='$country'";
    else
    $whereclause = " where $sCountry='$country'";


//if (!empty($date1) && !empty($date2))
 //       if(!empty($whereclause))
//              $whereclause = $whereclause." and (StartDate >= '$date1' and StartDate <= '$date2')";
  //      else
   //             $whereclause = " where (StartDate >= '$date1' and StartDate <= '$date2')";


if (!empty($CAM) && !empty($CAM))
        if(!empty($whereclause))
                $whereclause = $whereclause." and $sCAM ='$CAM'";
        else
                $whereclause = " where $sCAM ='$CAM'";        

}
        
else
          {
          $whereclause = stripslashes($_GET['where']);
          }

if (empty($typeofreport))
    $typeofreport = isset($_GET['typeofreport']) ? $_GET['typeofreport'] : "";

if (empty($cat))
    $cat = isset($_GET['cat']) ? $_GET['cat'] : ""; 

if ($typeofreport=="tec")
    if ($cat=="1")
        $tablename = "vwtrainingandeventcats_asn";
    else
        $tablename = "vwtrainingandeventcats_pep";
elseif ($typeofreport=="ec")
    $tablename = "vwelearningcat";
elseif ($typeofreport=="pc")
    $tablename = "vwpartnerscat";
elseif ($typeofreport=="pu")
    $tablename = "pep_user";
elseif ($typeofreport=="ac")
    $tablename = "vwaccreditation";
    
    
$where = urlencode($whereclause);

$sql = "select ".$choose." from ".$tablename.$whereclause." Group by ".$choose;

//echo $sql;

$page_name="create_report.php"; //  If you use this code with a different page ( or file ) name then change this 

if(strlen($start) > 0 and !is_numeric($start)){
    echo "Data Error";
    exit;
}

$eu = ($start - 0); 
$limit = 10;                                 // No of records to be shown per page.
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit;     

$linkID=mysql_connect(SM_DB_HOST,SM_DB_USER,SM_DB_PASS);
mysql_select_db(SM_DB_NAME, $linkID);  
//$result2=mysql_query($sql)or die('Error, query failed');

$query = mysql_query($sql);       
$nume = mysql_num_rows($query);  --> line 202

 echo $nume;
?>
<script language="javascript">

function checkData()
{
    var a = document.savereport.reportname.value;
    if (a=="")    
    {    
        alert("Please enter the report name !!");    
        return false;
    }
}

</script>

<?php
    echo "<form action=\"create_report.php\" name=\"savereport\" method=\"post\" onSubmit=\"return checkData();\">";
    echo "Report Name : <input type=\"text\" name=\"reportname\">";
    echo "<input type=\"hidden\" name=\"whereclause\" value=\"$whereclause\">";
    echo "<input type=\"hidden\" name=\"choose\" value=\"$choose\">";
    echo "<input type=\"hidden\" name=\"tablename\" value=\"$tablename\">";
    echo "<input type=\"Submit\" name=\"Submit\" value=\"Save Report\"><br>";
    echo "<input type=\"radio\" name=\"viewtype\" value=\"Public\" checked>Public";
    echo "<input type=\"radio\" name=\"viewtype\" value=\"Private\">Private";
    echo "</form>";
                
//paging start
$p_limit=100; // This should be more than $limit and set to a value for whick links to be breaked

@$p_f=$_GET['p_f'];								// To take care global variable if OFF
if(!($p_f > 0)) {                         // This variable is set to zero for the first page
$p_f = 0;
}

$p_fwd=$p_f+$p_limit;
$p_back=$p_f-$p_limit;
//////////// End of variables for advance paging ///////////////
/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
echo "<table align = 'center' width='70%'><tr><td  align='left' width='20%'>";
if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back&cat=$cat&where=$where&typeofreport=$typeofreport'><font face='Verdana' size='2'>PREV $p_limit</font></a>"; }
echo "</td><td  align='left' width='10%'>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0 and ($back >=$p_f)) { 
print "<a href='$page_name?start=$back&p_f=$p_f&cat=$cat&where=$where&typeofreport=$typeofreport'><font face='Verdana' size='2'>PREV</font></a>"; 
} 
//////////////// Let us display the page links at  center. We will not display the current page as a link ///////////
echo "</td><td align=center width='50%'>";
for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit){
$number = $i/10+1;
if($i <> $eu){
$i2=$i+$p_f;
echo " <a href='$page_name?start=$i&p_f=$p_f&cat=$cat&where=$where&typeofreport=$typeofreport'><font face='Verdana' size='2'>$number</font></a> ";
}
else { echo "<font face='Verdana' size='2' color=red>$number</font>";}        /// Current page is not displayed as link and given font color red

}

echo "</td><td  align='right' width='10%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume and $this1 <($p_f+$p_limit)) { 
print "<a href='$page_name?start=$next&p_f=$p_f&cat=$cat&where=$where&typeofreport=$typeofreport'><font face='Verdana' size='2'>NEXT</font></a>";} 
echo "</td><td  align='right' width='20%'>";
if($p_fwd < $nume){
print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd&cat=$cat&where=$where&typeofreport=$typeofreport'><font face='Verdana' size='2'>NEXT $p_limit</font></a>"; 
}
echo "</td></tr></table>";

echo "</td></tr></table>";
	  echo "<form action='export_report.php' method='post' target='_blank'>";
	  echo "<INPUT type=\"hidden\" name=\"report_type\" value=\"customized_report\">";
	  echo "<INPUT type=\"submit\" value=\"Export To Excel\">";
	  echo "</form>";
	  
//paging end
// echo $tablename.$whereclause.$choose;
// $groupby = " group by ".$choose;
$report = new display($dbf,"vwelearningreport","Company","Company","0");
$report->showreport2($dbf,$tablename,$select2,$whereclause." Group by ".$choose." limit $eu, $limit",$choose);

$out = "";
	 
	 for($i = 0; $i < count($select2); $i++)	
	 {
		$out .= $select2[$i]."\t";
	 } 

	 $out .= "\n";
	 
	$mymysql="SELECT ".$choose." FROM ".$tablename." ".$whereclause." Group by ".$choose;
	$myresult=mysql_query($mymysql);
	$fieldcount = mysql_num_fields($myresult);  --> line 295
		
	while($myrow=mysql_fetch_array($myresult))  --> line 297
	{
		for($k=0;$k<$fieldcount;$k++)
		{
			$out .= $myrow[$k]."\t";
			
		}
		$out .= ""."\n";
				
	}
     //echo $out;
	 $_SESSION["out_customized_report"] = $out;
        
?>

can anyone help me out?
i got this error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/emcasia/public_html/pepadmin/create_report.php on line 202
at line 295 & 297

Recommended Answers

All 3 Replies

hi and welcome to daniweb. Next time please start a new topic instead of bumping a really old topic. As for the problem, there is probably a bug in your query. So try replacing line 201 and 202 with the following

$query = mysql_query($sql) or die(mysql_error()); 
$nume = mysql_num_rows($query); // --> line 202

i got this error when i replace the code
writing file '/tmp/MYmK4UbH' (Errcode: 28)

what does it mean?
i am new

I checked an article and it appears that the problem is with the way mysql is operating. It is like if there is something wrong with the mysql temp files located in your /tmp/ directory. If this is wamp or xampp then I would suggest rebooting the mysql service and if that doesn't work then perhaps a google search on "mysql error code 28" might give you a better picture.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.