Jump to content

Downloading Database table with latest rows


saikiran

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
Link to comment
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

Link to comment
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
Link to comment
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



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.