confused_aswell Posted November 29, 2008 Share Posted November 29, 2008 Hi Is it possible to move the entries in a db entry to the left when downloading them to a csv file? In the script below under the sql query you will see that when the entry_suburb is empty it is replaced with the entry_city. But is it not possible just to move all of the entries to the right of the empty field left so there are no spaces? Here is the script I am currently using. Any suggestions would be great, Thanks. Phil <?php require('includes/application_top.php'); $limit = (int) $_POST['limit']; if ($limit > 0){ $limit = ' LIMIT '. $_POST['limit'] .', 98446744073709551615'; } else { $limit = null; // Nullify it so there is no way it can affect the SQL. } $replace = array( 'address_book_id' => '', 'customers_name' => 'Customer Job', 'entry_firstname' => 'First Name', 'entry_lastname' => 'Last Name', 'entry_street_address' => 'Billing Address1', 'entry_suburb' => 'Billing Address2', 'entry_city' => 'Billing Address3', 'customers_state' => 'Billing Address4', 'entry_postcode' => 'Billing Address5', 'customers_country' => 'Country', 'customers_email_address' => 'Email', 'customers_telephone' => 'Phone' ); function split_num($num){ if (substr($num, 0,1) == 1) { return $num; } else { $num = substr($num, 0, 5) . ' ' . substr($num, 5); return $num; } } $values = mysql_query("SELECT zen_orders.customers_name, zen_address_book.entry_firstname, zen_address_book.entry_lastname, zen_address_book.entry_street_address, zen_address_book.entry_suburb, zen_address_book.entry_city, zen_orders.customers_state, zen_address_book.entry_postcode, zen_orders.customers_country, zen_orders.customers_telephone, zen_orders.customers_email_address FROM (zen_address_book INNER JOIN zen_orders ON zen_address_book.customers_id = zen_orders.customers_id) INNER JOIN zen_customers ON (zen_address_book.address_book_id = zen_customers.customers_default_address_id) AND (zen_address_book.customers_id = zen_customers.customers_id)$limit"); $i=0; while ($rowr = mysql_fetch_assoc($values)) { if($rowr['entry_suburb'] ==""){ $rowr['entry_suburb'] = $rowr['entry_city']; } if(!preg_match('#\x20#', $rowr['customers_telephone'], $match)){ // does not find a space... $rowr['customers_telephone'] = split_num($rowr['customers_telephone']); } if($i==0) { foreach(array_keys($rowr) as $title) $csv_output .= '"'.str_replace(array_keys($replace), $replace, $title).'",'; $csv_output .= "\n"; } foreach ($rowr as $key => $value) { $csv_output .= '"'.$value.'",'; } $csv_output .= "\n"; $i++; } $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; // Footer require(DIR_WS_INCLUDES . 'footer.php'); // End of footer require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> ?> Link to comment https://forums.phpfreaks.com/topic/134781-if-statement/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.