Delaran Posted April 27, 2007 Share Posted April 27, 2007 So I'm trying to create a .php page which will query my database, save the results into a .csv format (excel), and then force the download upon the person accessing the page (giving them an open/save option). So far I've been using aliases to assign the values from the two tables I'm using, but I'm unsure of how to continue with the saving part. If anyone could give me a clue as to what command to use, I'd be greatful. I'm using MySQL version 5.0.16 and PHP 4.4.1, if that helps. Thanks in advance -- you guys rock. // create query $query = "SELECT AC.contact_name, C.company_name, C.addr_line1, C.addr_line2, C.city, C.state, C.zip, C.phone FROM cust_contact_info AS C, additional_contacts AS AC WHERE AC.cust_contact_info_id = C.cust_contact_info_id;"; // execute queries $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); Link to comment https://forums.phpfreaks.com/topic/48965-saving-queries-to-an-extension/ Share on other sites More sharing options...
Delaran Posted April 27, 2007 Author Share Posted April 27, 2007 So I've gotten a bit farther and I think I have to use $handle = fopen("/home/pwalton/ht_docs/distributionlist.csv", "r"); to get the file to download, but when I use it in conjunction with my SQL statement is tells me I "Can't create/write to file '/home/~pwalton/ht_docs/distributionlist.csv' (Errcode: 2)". This is my statement: $query = "SELECT AC.contact_name, C.company_name, C.addr_line1, C.addr_line2, C.city, C.state, C.zip, C.phone FROM cust_contact_info AS C, additional_contacts AS AC WHERE AC.cust_contact_info_id = C.cust_contact_info_id INTO OUTFILE '/home/pwalton/ht_docs/distributionlist.csv'"; If anyone knows what the correct function of this would be I'd greatly appreciate any help. Link to comment https://forums.phpfreaks.com/topic/48965-saving-queries-to-an-extension/#findComment-239922 Share on other sites More sharing options...
Delaran Posted April 27, 2007 Author Share Posted April 27, 2007 Alright, after numerous attempts I've finally read a PHPFreaks tutorial on the site which gave me what I wanted. Here's another problem I ran into that perhaps won't be asking a stupid question: // create query $select = "SELECT C.cust_contact_info_id, AC.contact_name, C.company_name, C.addr_line1, C.addr_line2, C.city, C.state, C.zip, C.phone FROM cust_contact_info AS C, additional_contacts AS AC WHERE AC.cust_contact_info_id = C.cust_contact_info_id This query will bring back all the data I need, but there is a problem -- sometimes the information listed will omit a company name that does not have a contact name! This seems like an easy fix, probably something to do with an OR command but I'm unsure of how the syntax would work to include the values when contact_name is a null. Anyone? Link to comment https://forums.phpfreaks.com/topic/48965-saving-queries-to-an-extension/#findComment-240031 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.