Jump to content


Photo

Downloading Database table with latest rows


  • Please log in to reply
7 replies to this topic

#1 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 03 August 2006 - 10:55 AM

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

<?
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
}
}
?>


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.

Everytime, when user presses , we are getting the full table

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.

Can anyone help me out in this regard.


cheers
saikiran
saisen76@hotmail.com


#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 11:06 AM

$sql = "select * from blocked_temp_cus" WHERE x = 'y'
Tell me the problem, I will try tell you the solution

#3 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 03 August 2006 - 11:13 AM

hi,

$sql = "select * from blocked_temp_cus" WHERE x = 'y'


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



#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 11:25 AM

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....
Tell me the problem, I will try tell you the solution

#5 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 03 August 2006 - 11:34 AM

hi,

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....


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

#6 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 12:11 PM

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)
Tell me the problem, I will try tell you the solution

#7 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 03 August 2006 - 12:18 PM

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

#8 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 03 August 2006 - 12:44 PM

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.

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


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


thank you once again

cheers
saikiran








0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users