download query result

F

fikru

Guest
I would like to download query result from mysql table and save it as a FASTA file. Can this be done from DaDaBIK? Here is the code that I am interested in using:

<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=sequences.seq");
if(preg_match("/mac/i", $_SERVER['HTTP_USER_AGENT']))
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");// always modified
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
}
$sesid = $_GET["ses"];

$sql = "SELECT * FROM my_table$sesid";
$link = mysql_connect ("localhost", "", "")
or die ("Could not connect");
mysql_select_db("my_db");
$result = mysql_query ($sql)
or die ("Could not execute query");
$numFields = mysql_num_fields($result);
while ($row = mysql_fetch_row($result))
{
$name=$row[3];
$uni=$row[1];
$ref=$row[2];
$seq = $row[29];
$size = strlen(trim($seq));
$seq=chunk_split($seq, 50, "\n");
$FASTA=sprintf(">%s|%s|%s|%sbp\n%s", $name,$uni,$ref,$size,trim($seq));
echo $FASTA;
echo "\n";
}
mysql_close($link);
?>
 
F

fikru

Guest
Has anyone out there tried to use a code similar to the one I posted with DaDaBIK to save a query result to the local disk?
 
E

Eugenio

Guest
fikru wrote:

> Has anyone out there tried to use a code similar to the one I
> posted with DaDaBIK to save a query result to the local disk?

I don't know much about FASTA files so I can't help you.



(Latest version of DaDaBIK when this message was posted: 2.2.1)
 
F

fikru

Guest
Eugenio,

Is there a way to save the result of a search result in DaDaBIK? I am working with DNA sequence database and I want to be able to save the search results from the database in either FASTA, GenBank or Excel formats. I have the code to convert the data into those formats. What I am having difficulty with is integrating those codes to work within DaDaBIK. Thanks for your time and DaDaBIK.

Fikru

Eugenio wrote:

> fikru wrote:
>
> > Has anyone out there tried to use a code similar to the one
> I
> > posted with DaDaBIK to save a query result to the local
> disk?
>
> I don't know much about FASTA files so I can't help you.
>
>
>
> (Latest version of DaDaBIK when this message was posted:
> 2.2.1)

 
E

Eugenio

Guest
fikru wrote:

> Eugenio,
>
> Is there a way to save the result of a search result in
> DaDaBIK? I am working with DNA sequence database and I want to
> be able to save the search results from the database in either
> FASTA, GenBank or Excel formats. I have the code to convert the
> data into those formats. What I am having difficulty with is
> integrating those codes to work within DaDaBIK. Thanks for your
> time and DaDaBIK.

Hi,
I'm sorry it's impossible to explain in a few lines how to apply a major hack like the one you need, anyway version 3.0 which I'm going to release has also an "Export to CSV" feature.




(Latest version of DaDaBIK when this message was posted: 2.2.1)
 
S

Scott

Guest
I have exported data using a custom SQL query that is inserted into this php script. I implemented a query that outputs mailing addresses to print mailing labels using Microsoft Word. So any user can click on the link and a "Save As" window pops up in IE to save the spreadsheet.

http://www.hotscripts.com/cgi-bin/dload.cgi?ID=13890


This may be a of some help also:
http://www.stargeek.com/scripts.php?script=2&cat=sql


Scott
 
F

fikru

Guest
Scott wrote:

> I have exported data using a custom SQL query that is
> inserted into this php script. I implemented a query that
> outputs mailing addresses to print mailing labels using
> Microsoft Word. So any user can click on the link and a "Save
> As" window pops up in IE to save the spreadsheet.
>
> http://www.hotscripts.com/cgi-bin/dload.cgi?ID=13890
>

Thanks, Scott. This script saves the whole table in my database. What I would like to be able to save is the result of a query on the table. In other words, I want to plug in different WHERE clauses on the SELECT statement depending on the query: $sql = "Select * from $DB_TBLName WHERE ..." For example, if my table contains 100 records and my search query returned 10 records, I just want to save the 10 records that were returned to the spreadsheet. This is what I have not been able to figure out.

>
> This may be a of some help also:
> http://www.stargeek.com/scripts.php?script=2&cat=sql
>

I have also tried this code. Same result.

Fikru

 
S

Scott

Guest
Using the first script from the hotscripts.com link, "php_doc_xls_gen.php", just change the sql statement in the code. Here is what mine code looks like. I just commented the default query definition and inserted my own to return ONLY mailing addresses from the 50 other fields that I have in the DB. I hope this helps.

//DEFINE SQL QUERY:
//you can use just about ANY kind of select statement you want -
//edit this to suit your needs!

//$sql = "Select * from $DB_TBLName";
$sql = "SELECT `FirstName` , `LastName` , `Address` , `City` , `State` , `PostalCode` FROM `memberlist`";
 
Top