saikiran Posted August 3, 2006 Share Posted August 3, 2006 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.1header("Cache-Control: post-check=0, pre-check=0", false);header("Pragma: no-cache"); // HTTP/1.0header("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.cheerssaikiran[email protected] Link to comment https://forums.phpfreaks.com/topic/16439-downloading-database-table-with-latest-rows/ Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 $sql = "select * from blocked_temp_cus" WHERE x = 'y' Link to comment https://forums.phpfreaks.com/topic/16439-downloading-database-table-with-latest-rows/#findComment-68452 Share on other sites More sharing options...
saikiran Posted August 3, 2006 Author Share Posted August 3, 2006 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 .cheerssaikiran Link to comment https://forums.phpfreaks.com/topic/16439-downloading-database-table-with-latest-rows/#findComment-68455 Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 noThe query checks where something is somethingFor exampleyou have a field with id_numSELECT * FROM table WHERE id_num > 15;This should show all results where id_num is over 15(16, 17, 18.... Link to comment https://forums.phpfreaks.com/topic/16439-downloading-database-table-with-latest-rows/#findComment-68461 Share on other sites More sharing options...
saikiran Posted August 3, 2006 Author Share Posted August 3, 2006 hi,[quote]The query checks where something is somethingFor exampleyou have a field with id_numSELECT * 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 ????cheerssaikiran Link to comment https://forums.phpfreaks.com/topic/16439-downloading-database-table-with-latest-rows/#findComment-68465 Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 You would need to store it somewherefor example, another table saying last update at id 16then you grab that number, andWHERE id_num > 16(Remember greater than, it does not include the 16) Link to comment https://forums.phpfreaks.com/topic/16439-downloading-database-table-with-latest-rows/#findComment-68479 Share on other sites More sharing options...
saikiran Posted August 3, 2006 Author Share Posted August 3, 2006 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 suggestionscheerssaikiran Link to comment https://forums.phpfreaks.com/topic/16439-downloading-database-table-with-latest-rows/#findComment-68486 Share on other sites More sharing options...
saikiran Posted August 3, 2006 Author Share Posted August 3, 2006 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 againcheerssaikiran Link to comment https://forums.phpfreaks.com/topic/16439-downloading-database-table-with-latest-rows/#findComment-68503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.