Jump to content

Archived

This topic is now archived and is closed to further replies.

saikiran

Downloading Database table with latest rows

Recommended Posts

hi,

I am developing an web-app, where the client can download the database table as a .csv file. I am doing this using the below script

[quote]<?
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
header("Cache-control: private"); header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=block_registration.csv");
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
require ("config.php"); //db connection
$sql = "select * from blocked_temp_cus";
$result = mysql_query($sql);
if ($result){
//$sql = "select * from ads";
//$result = mysql_query($sql,$conn);
$count = mysql_num_fields($result);
while ($rows = mysql_fetch_array($result)){

for ($i=0;$i<$count;$i++){
echo $rows[$i].", "; //data
}
echo "\n"; //new line
}
}
?>[/quote]

This works pretty well. Everytime, they click the download link, this file generates the .csv file and puts all the rows into the excel sheet completely.

[color=red]Everytime, when user presses , we are getting the full table [/color]

[color=red]Now, what we want is whenever we click the link, i want to download the latest records that i have inserted, instead of downloading the complete table once again.[/color]

Can anyone help me out in this regard.


cheers
saikiran
saisen76@hotmail.com

Share this post


Link to post
Share on other sites
hi,

[quote]$sql = "select * from blocked_temp_cus" WHERE x = 'y'[/quote]

Thank you for your reply. But, i am not a php expert, what i understand from your code is that, we have to add one column or field, which will check for some value Y/N to be there.

If it is Yes, then it will execute the script ?

Can you please elaborate it so that i can do the rest .


cheers
saikiran

Share this post


Link to post
Share on other sites
no
The query checks where something is something
For example
you have a field with id_num
SELECT * FROM table WHERE id_num > 15;
This should show all results where id_num is over 15
(16, 17, 18....

Share this post


Link to post
Share on other sites
hi,

[quote]The query checks where something is something
For example
you have a field with id_num
SELECT * FROM table WHERE id_num > 15;
This should show all results where id_num is over 15
(16, 17, 18....[/quote]

Sorry to say this.... i am still not able to understand.How could i generate a latest back up of a table using the above script.

Suppose, assume that id_num is my auto-generated record id, how could i know, whether this is the latest back up or not ????



cheers
saikiran

Share this post


Link to post
Share on other sites
You would need to store it somewhere

for example, another table saying last update at id 16
then you grab that number, and
WHERE id_num > 16
(Remember greater than, it does not include the 16)

Share this post


Link to post
Share on other sites
hi,

This is wat i am looking for , i hope so....let me work in this way...


i hope, this will solve my problem probably.


Thank you once again for your suggestions

cheers
saikiran

Share this post


Link to post
Share on other sites
hi,

one small doubt once again, i am clear upto getting the latest row id and storing it in another table, and while clicking the download link, we have to check whether the id is greater than the stored one,

in this case, does we have to use join with the two tables using the id column..if yes then what will be the syntax for join.

[quote]$sql1 = "select * from table1, table2, where table1.id=table2.id && table2.id>$last_value";[/quote]

just tell me whether i am doing it wrong or right.


thank you once again

cheers
saikiran



Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.