| | |
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 15 Days Ago
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 15 Days Ago
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; 15 Days Ago at 9:12 am.
0
#5 15 Days Ago
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: 49
Reputation:
Solved Threads: 6
0
#6 15 Days Ago
•
•
•
•
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 15 Days Ago
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; 15 Days Ago 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 15 Days Ago
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
| Thread Tools | Search this Thread |
5.2.10 action apache api array basic beginner binary broken cakephp checkbox class classes cms code computing confirm cron curl database date delete destroy display domain dynamic echo echo$_get[x]changingitintovariable... email error fatalerror file files folder form forms function functions google header href htaccess html iframe image include indentedsubcategory insert ip javascript joomla limit link load local login mail malfunction menu mlm mod_rewrite multiple mysql mysqlquery neutrality oop paypal pdf php query radio random record reference remote return script search server sessions sockets source space sql syntax system table thesishelp tutorial unset update upload url validation validator variable video web window.onbeforeunload=closeme; youtube





