Page 1 of 1

replay me please

Posted: Mon Oct 12, 2009 8:18 am
by shakawat
how to specify directory below program
<?php

//Connection
//$server = "localhost"; //Host name
//$username = "root"; //DB username
//$password = ""; //DB Password
//$dbname = "mytrack"; //DB name
//$tablename = "updatelocation"; //table name
include_once("lib/global.php");
include_once("lib/class.connection.php");
include_once("class/class.mysqldbdriver.php");
// Creating database connectin
$conn = new connection();
$conn->connect($host,$user,$pass,$db);

$rows_per_page =10; //Total number of records to present in each page

//DB connection
// $conn = mysql_connect($server,$username,$password);
//mysql_select_db($dbname,$conn);

//Queries
$querycount = "SELECT count(*) FROM sender_t";
$query = "SELECT *FROM sender_t";


//For page count
$result = mysql_query($querycount) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$lastpage = ceil($numrows/$rows_per_page); //Calculate total number of files to be generated
$pageno = 1; //intialize page as 1

//Generating files in CSV format
for($i=1; $i<=$lastpage; $i++) {

//Fixing limit
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$filename = "shipment" . $i . ".csv";
$fp = fopen($filename, "w");

$res = mysql_query("$query $limit");

// fetch a row and write the column names out to the file
$row = mysql_fetch_assoc($res);
$line = "";
$comma = "";
foreach($row as $name => $value) {
$line .= $comma . '"' . str_replace('"', '""', $name) . '"';
$comma = ",";
}
$line .= "\n";
fputs($fp, $line);

// remove the result pointer back to the start
mysql_data_seek($res, 0);

// and loop through the actual data
while($row = mysql_fetch_assoc($res)) {

$line = "";
$comma = "";
foreach($row as $value) {
$line .= $comma . '"' . str_replace('"', '""', $value) . '"';
$comma = ",";
}
$line .= "\n";
fputs($fp, $line);
}
$pageno = $pageno+1; //count page number for next file generation

}
fclose($fp);
echo"<script>

alert('Excel file Has Been Creted For Shipment Ststus ');
window.location = 'index2.php';
</script>"

?>

Re: replay me please

Posted: Mon Oct 12, 2009 8:25 am
by Weiry
Please read Before Post Read: General Posting Guidelines
Specifically "in a nutshell" Number 9.
shakawat wrote:how to specify directory below program
Also, can you elaborate on your problem?
Without going through each line of code, i have no idea what it is supposed to do and what problem your having with the code.