9 msgScripts slowing down?
2 msgcalling rsync from php script
1 msgcn2 dot php.net can't be included in the mail.
5 msgtracking Mials Which were bounced.
21 msgGood HTML parser needed
4 msgusing variable in php form before the form is P...
2 msgphp_svn.dll with Apache/2.0.63
1 msgsession.auto_start Linux vs Windows
4 msgPermissions set on php script question
11 msgReplacing accented characters by non-accented c...
6 msgconvert query result to array
2 msgPHP and a misbehaving contact form
10 msgGood XML Parser
3 msgIgnore Tags
4 msgmysql_pconnect issue

creating an xls file from mysql data
\ Richard Kurth (11 May 2008)
. \ Andrew Johnstone (11 May 2008)
. \ Richard Kurth (12 May 2008)
. . \ Chris (13 May 2008)
. . . \ Ray Hauge (13 May 2008)
. . . . \ Chris (13 May 2008)
. . . \ Richard Kurth (13 May 2008)
. . . . \ Chris (13 May 2008)

2 msgHelp with a foreach statement
5 msgCan I make EasyPHP on Windows allow remote conn...
3 msgSafe mode story
18 msgPHP-MYSQL Error: Can't connect to MySQL socket....
Subject:creating an xls file from mysql data
Group:Php-general
From:Richard Kurth
Date:11 May 2008


 

This script will create an xls file from the data that is sent to it
When I run this it only gets one recored and it is supposet to get all
the records that are past by the $_POST[selectedcontactlist]
I think I have a } in the wrong place but I can not figure it out
anybody have a suggestion

$_POST[selectedcontactlist]="3,45,65,23,12,4,56"; //this is a sample of
what is past

$ExplodeIt = explode(",",rtrim($_POST[selectedcontactlist],","));
$Count = count($ExplodeIt);
for ($i=0; $i < $Count; $i++) {
$sql = "SELECT * FROM contacts WHERE id = '$ExplodeIt[$i]'";
$sql_result = query($sql);
$count = mysql_num_fields($sql_result);

for ($i = 0; $i < $count; $i++){
$header .= mysql_field_name($sql_result, $i)."\t";
}

while($row = mysql_fetch_row($sql_result)){
$line = '';
foreach($row as $value){
if(!isset($value) || $value == ""){
$value = "\t";
}else{
# important to escape any quotes to preserve them in the data.
$value = str_replace('"', '""', $value);
# needed to encapsulate data in quotes because some data might be multi
line.
# the good news is that numbers remain numbers in Excel even though quoted.
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
}
# this line is needed because returns embedded in the data have "\r"
# and this looks like a "box character" in Excel
$data = str_replace("\r", "", $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == "") {
$data = "\nno matching records found\n";
}

# This line will stream the file to the user rather than spray it across
the screen
header("Content-type: application/octet-stream");

# replace excelfile.xls with whatever you want the filename to default to
header("Content-Disposition: attachment; filename=excelfile.xls");
header("Pragma: no-cache");
header("Expires: 0");

echo $header."\n".$data;


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



© 2004-2008 readlist.com