| | |
Button php export table data
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 8
Reputation:
Solved Threads: 0
Hi! I need a button in php code, that when i click on that button it export's my SELECT to a text file or excell file..
i searched.. there's a lot of program's that make that.. but i don't want that.. i want to make on my webpage a simple code button that when someone click there it save's the content of a table..
thanks a lot
i searched.. there's a lot of program's that make that.. but i don't want that.. i want to make on my webpage a simple code button that when someone click there it save's the content of a table..
thanks a lot
0
#3 Nov 7th, 2009
Hey.
What data are you looking to export?
Fetching data from a form and writing it to a file is fairly simple. We just have no idea what sort of data you are using, and without knowing that we can't really say anything for certain.
We need to see your code. The form that contains your data.
What data are you looking to export?
Fetching data from a form and writing it to a file is fairly simple. We just have no idea what sort of data you are using, and without knowing that we can't really say anything for certain.
We need to see your code. The form that contains your data.
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
And use [code] tags!
•
•
Join Date: Nov 2009
Posts: 8
Reputation:
Solved Threads: 0
0
#4 Nov 7th, 2009
thanks a lot for reply
OUTPUT:
http://i.imagehost.org/0085/example.jpg
i wanted to save that table content that show's in the figure.. latitude, longitude and data, to a text file or excell file...
you know now what i mean?
PHP Syntax (Toggle Plain Text)
$db = new Banco(); $id = $_REQUEST['id']; $datai = $_REQUEST['iData']; $dataf = $_REQUEST['fData']; $rs = $db->Query("SELECT * FROM localizacao WHERE (local_clien_id='$id') AND ((data>=to_date('$datai', 'dd/mm/yyyy')) AND (data<=to_date('$dataf', 'dd/mm/yyyy')+1)) ORDER BY local_id asc"); if(pg_num_rows($rs)>0) { while($myrow = pg_fetch_assoc($rs)) { printf ("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", $myrow['latitude'], $myrow['longitude'], $myrow['altitude'], $myrow['data']); } }
OUTPUT:
http://i.imagehost.org/0085/example.jpg
i wanted to save that table content that show's in the figure.. latitude, longitude and data, to a text file or excell file...
you know now what i mean?
Last edited by jppr03; Nov 7th, 2009 at 9:12 am.
0
#5 Nov 7th, 2009
Ok, I see.
You can have PHP create whatever output you want out of that.
For example, to create a XML file and save it on the server, you can do:
Creating a Excell file is a bit more complicated (Microsoft don't play well with others), but Excell should be able to read basic XML files like these.
You can have PHP create whatever output you want out of that.
For example, to create a XML file and save it on the server, you can do:
php Syntax (Toggle Plain Text)
// <snipped the DB code> $output = '<?xml version="1.0" encoding="UTF-8"?><root>'; if(pg_num_rows($rs)>0) { while($myrow = pg_fetch_assoc($rs)) { $output .= sprintf('<row><latitude>%s</latitude><longitude>%s</longitude><altitude>%s</altitude><date>%s</date></row>', $myrow['latitude'], $myrow['longitude'], $myrow['altitude'], $myrow['data']); $output .= "\n"; } } $output .= '</root>'; file_put_contents('/path/to/my/file.xml', $output);
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
And use [code] tags!
•
•
Join Date: Oct 2009
Posts: 57
Reputation:
Solved Threads: 6
0
#6 Nov 7th, 2009
•
•
•
•
Ok, I see.
You can have PHP create whatever output you want out of that.
For example, to create a XML file and save it on the server, you can do:
Creating a Excell file is a bit more complicated (Microsoft don't play well with others), but Excell should be able to read basic XML files like these.php Syntax (Toggle Plain Text)
// <snipped the DB code> $output = '<?xml version="1.0" encoding="UTF-8"?><root>'; if(pg_num_rows($rs)>0) { while($myrow = pg_fetch_assoc($rs)) { $output .= sprintf('<row><latitude>%s</latitude><longitude>%s</longitude><altitude>%s</altitude><date>%s</date></row>', $myrow['latitude'], $myrow['longitude'], $myrow['altitude'], $myrow['data']); $output .= "\n"; } } $output .= '</root>'; file_put_contents('/path/to/my/file.xml', $output);
Basicly you can create an .xls file and fill it with html.
//K0ns3rv
0
#8 Nov 7th, 2009
Also, forgot to mention.
If you would rather send the file to the user, to allow him to download it, you can do this instead of the
This prompts a download box in all the major browsers.
If you would rather send the file to the user, to allow him to download it, you can do this instead of the
file_put_contents . php Syntax (Toggle Plain Text)
header('content-type: text/xml'); header('content-disposition: attachment; filename=data_export.xml'); echo $output;
Last edited by Atli; Nov 7th, 2009 at 11:26 am.
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
And use [code] tags!
0
#10 Nov 7th, 2009
Consider this code.
It has a form where a user enters the start and end date, and the PHP code compiles a XML file with all the data from a table that were created in that time-frame.
I created it for a MySQL database, but you can easily re-write the database part to fit your database. I just don't have anything else to test on my end.
Does that help at all?
It has a form where a user enters the start and end date, and the PHP code compiles a XML file with all the data from a table that were created in that time-frame.
I created it for a MySQL database, but you can easily re-write the database part to fit your database. I just don't have anything else to test on my end.
php Syntax (Toggle Plain Text)
<?php if(isset($_POST['StartDate'], $_POST['EndDate'])) { $dbLink = new mysqli('localhost', 'usr', 'pwd', 'dbName'); // Fetch the data $start = $dbLink->real_escape_string($_POST['StartDate']); $end = $dbLink->real_escape_string($_POST['EndDate']); $sql = "SELECT * FROM `news` WHERE `Created` BETWEEN '{$start}' AND '{$end}'"; $result = $dbLink->query($sql); // Create the XML output $output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root>\n"; if($result->num_rows > 0) { while($myrow = $result->fetch_assoc()) { $output .= "\t<row>\n"; foreach($myrow as $_name => $_value) { $output .= "\t\t<$_name>$_value</$_name>\n"; } $output .= "\t</row>\n"; } } $output .= "</root>"; // Send it as a XML file for download header('content-type: text/xml'); header('content-disposition: attachment; filename=data_export.xml'); echo $output; exit; } else { ?> <!DOCTYPE html> <html> <head> <title>Data Export Thingie</title> </head> <body> <h1>Export some dataz!</h1> <form action="?" method="post"> <label for="StartDate">Start Date:</label> <input type="text" name="StartDate" id="StartDate" value="YYYY-MM-DD HH:MM" /><br /> <label for="EndDate">End Date:</label> <input type="text" name="EndDate" id="EndDate" value="YYYY-MM-DD HH:MM" /><br /> <input type="submit" /> </form> </body> </html> <?php } ?>
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
And use [code] tags!
![]() |
Similar Threads
- Exporting .php to HTML, PDF, EXCEL, TEXT, CSV, ODS and SXC (PHP)
- Export datagridview data to excel (C#)
- Help with php script to export mysql data and import data (PHP)
- Display multiple data entries froma single form (JSP)
- result multiple table data? (PHP)
- Export Mysql data to CSV (also from diferent tables) (PHP)
- How we can use download button on a php page (PHP)
- download table data from mysql (PHP)
- Populate Listboxes with table data (VB.NET)
- php wont submit data into the database (PHP)
Other Threads in the PHP Forum
- Previous Thread: Dynamic Array?
- Next Thread: Dynamic title errors
Views: 654 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl customizableitems database date development directory display download dynamic echo email error file files folder form forms forum function functions google headmethod href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail malfunctioning menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





