But when i set these headers again, it saves everything present on the screen to the csv file, which i don't want. i just want to save my query results in the csv file. How do i do that ?
Second, Clicking on anything leads to the download to begin , which is again something not desirable.
Pls tell me wahts wrong with the code here !!!
<?php
###########################################################################
include("../libs/config_main.php");
include("../libs/auth.php");
##CODE BELOW HERE
#print("(\$auth_userid, \$auth_userperms)🙁$auth_userid, $auth_userperms)<BR>");
AuthCheck(10,''); //Admins higher than this level can access.
#print("Got here.");
##CODE ABOVE HERE
$filename = "data.csv";
header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename=$filename" );
header( "Content-Description: Excel output" );
$PAGEtitle = "Manager Control";
include("${ROOT}admin/absheader.htm");
##############Page Navigation ##############
$limit = 100;
if (!$offset)
{
$offset = 0;
}
function pagenav()
{
global $limit,$offset,$numpage,$where;
if ($where)
{
$safewhere=urlencode($where);
}
echo "<TABLE CELLPADDING=0 BORDER=0 CELLSPACING=5 WIDTH=100% align=\"center\"><tr> </tr><TR align=center><TD ALIGN='center'>";
if ($offset>=$limit)
{
$newoff=$offset-$limit;
echo "<A HREF=\"$PHP_SELF?offset=$newoff\">PREV</A>";
}
else
{
echo "PREV";
}
echo "<font size=2><b> </b></font> ";
for ($i=1;$i<=$numpage;$i++)
{
if ((($i-1)$limit)==$offset)
{
print "$i ";
}
else
{
$newoff=($i-1)$limit;
echo "<A HREF=\"$PHP_SELF?offset=$newoff\">
$i</A>";
}
}
echo " ";
if ($offset!=$limit*($numpage-1) && $offset=="NULL")
{
$newoff=$offset+$limit;
echo "<A HREF=\"$PHP_SELF?offset=$newoff\">NEXT</A></TD>";
}
else
{
echo "NEXT";
}
echo "</TR></TABLE>";
} // END FUNCTION
###########################################################################
?>
<!-- CONTENT ------------------------------------------------------------------>
<!-- CONTENT ------------------------------------------------------------------>
<?
if ("y" == $showenv) {
phpinfo();
}
?>
<TABLE WIDTH="95%" BORDER="0" CELLSPACING="3" CELLPADDING="2" ALIGN="CENTER">
<TR>
<TD CLASS="form" COLSPAN=2>
<P>
Coming soon.
</P>
</TD>
</TR>
</TABLE>
<!-- /CONTENT ------------------------------------------------------------------>
<!-- /CONTENT ------------------------------------------------------------------>
<?php
##########################Selecting & connecting to the database
$Host = "localhost";
$Database = "joke";
$User = "root";
$Password = "";
if (!($link = mysql_pconnect($Host, $User, $Password)))
{print "Error connect to host";
exit();
}
if(!mysql_select_db($Database , $link)){
print "Error Selecting database";
exit();
}
if ($action== checkit1){
function download(){
$result = mysql_query("SELECT * from subscribe_joke");
/* $filename = "data.csv";
$fp = fopen($filename, "w") or die("Can't open file.");
for($j=0; $j< mysql_num_fields($result); $j++){
fwrite($fp,mysql_field_name($result, $j));
} //end for loop
for($j=0; $j< mysql_num_rows($result); $j++){
$row_array = mysql_fetch_row($result);
for($k=0 ;$k< mysql_num_fields ; $k++){
fwrite($fp,"$row_array[$k]\t");
}
fwrite($fp, "\n");
}
fclose($fp);
} //end function
download(); */
}
if ($action ==checkit) {
for($i=0;$i<count($action_items);$i++) {
$query = sprintf("DELETE from subscribe_joke where id = '%s'", $action_items[$i]);
mysql_query($query);
}
}
$result = mysql_query("SELECT * from subscribe_joke");
?>
<html>
<body>
<TABLE WIDTH="95%" BORDER="1" CELLSPACING="3" CELLPADDING="2" ALIGN="CENTER">
<tr>
<td width="7%">Check to delete!</td>
<td align="left"><b>Email</b></td>
<td ><b>Subscribed</b></td>
<td ><b>Happy Hours</b></td>
<td><b>Date subscribed</b></td>
</tr>
<tr>
<form method="post" name="deleteformlist" ACTION="<? print ("${PHP_SELF}?$cacheid&action=checkit"); ?>">
<?
while ($row = mysql_fetch_array($result)) {
printf('<tr><td><input type="checkbox" name="action_items[]" value="%s"></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>', $row["id"], $row["email"], $row["subscribe_yn"], $row["happy_hrs"], $row["sub_date"]);
}
?>
<tr><td colspan=3><input type="submit" name="submit" value="Delete Records"></td></tr>
</form>
<tr>
<form method ="post" name="downloadFile" Action="<? print ("${PHP_SELF}?$cacheid&action=checkit1"); ?>">
<tr><td colspan=3><input type="submit" name="submit" value="Download File"></td></tr>
</form>
</table>
<? pagenav(); ?>
</body>
</html>
<?
###########################################################################
include("${ROOT}admin/absfooter.htm");
###########################################################################
?>