Jump to content

inserting a if statement


confused_aswell

Recommended Posts

Hi

 

I am trying to insert a if statement into this script so that if the fields in one of the entries column entry_suburb is empty then it will be filled with the column entry_city.

 

I would appreciate any help please.

 

Thanks,

 

Phil

 

Here is the if statement

<?php if (empty($entry_suburb)) $entry_suburb ='entry_city';?>

 

Here is the script

<?php$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");

$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',
'entry_state' => 'Billing Address4',
'entry_postcode' => 'Billing Address5',
'customers_email_address' => 'Email',
'customers_telephone' => 'Phone'

);
function split_num($num){ 
    $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_address_book.entry_state, zen_address_book.entry_postcode, 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)");


if (empty($entry_suburb)) $entry_suburb ='entry_city';



$i=0;
while ($rowr = mysql_fetch_assoc($values)) { 
    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;

?> 

Link to comment
https://forums.phpfreaks.com/topic/127154-inserting-a-if-statement/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.