1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Add To An Array

Discussion in 'PHP' started by T0PS3O, Feb 9, 2005.

  1. #1
    I don't like arrays...

    I need to add a key/value pair to an array.

    Now it's:

    $sql_data_array = array('customers_id' => $customer_id,
                                      'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'],
                                      'customers_company' => $order->customer['company'],
                                      'customers_street_address' => $order->customer['street_address'],
                                      'customers_suburb' => $order->customer['suburb'],
                                      'customers_city' => $order->customer['city'],
                                      'customers_postcode' => $order->customer['postcode'],
                                      'customers_state' => $order->customer['state'],
                                      'customers_country' => $order->customer['country']['title'],
                                      'customers_telephone' => $order->customer['telephone'],
                                      'customers_email_address' => $order->customer['email_address'],
                                      'customers_address_format_id' => $order->customer['format_id'],
                                      'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'],
                                      'delivery_company' => $order->delivery['company'],
                                      'delivery_street_address' => $order->delivery['street_address'],
                                      'delivery_suburb' => $order->delivery['suburb'],
                                      'delivery_city' => $order->delivery['city'],
                                      'delivery_postcode' => $order->delivery['postcode'],
                                      'delivery_state' => $order->delivery['state'],
                                      'delivery_country' => $order->delivery['country']['title'],
                                      'delivery_address_format_id' => $order->delivery['format_id'],
                                      'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'],
                                      'billing_company' => $order->billing['company'],
                                      'billing_street_address' => $order->billing['street_address'],
                                      'billing_suburb' => $order->billing['suburb'],
                                      'billing_city' => $order->billing['city'],
                                      'billing_postcode' => $order->billing['postcode'],
                                      'billing_state' => $order->billing['state'],
                                      'billing_country' => $order->billing['country']['title'],
                                      'billing_address_format_id' => $order->billing['format_id'],
                                      'payment_method' => $order->info['payment_method'],
                                      'cc_type' => $order->info['cc_type'],
                                      'cc_owner' => $order->info['cc_owner'],
                                      'cc_number' => $order->info['cc_number'],
                                      'cc_expires' => $order->info['cc_expires'],
                                      'date_purchased' => 'now()',
                                      'orders_status' => $order->info['order_status'],
                                      'currency' => $order->info['currency'],
                                      'currency_value' => $order->info['currency_value']);
    PHP:
    I need to add to this, at the very end:

    'purchase_without_account' => '1'

    Just as if the original (cropped) would have been like this:

               'cc_number' => $order->info['cc_number'],
                                      'cc_expires' => $order->info['cc_expires'],
                                      'date_purchased' => 'now()',
                                      'orders_status' => $order->info['order_status'],
                                      'currency' => $order->info['currency'],
                                      'currency_value' => $order->info['currency_value'],
    'purchase_without_accoun't => '1');
    PHP:
    Comprendo?

    Can I simply do
    $sql_data_array .= array('purchase_without_account' => '1'); 
    PHP:
    ? Just as if it was a normal string? (note the dot .= )

    Or is it like
    $sql_data_array[purchase_without_account] = 1;
    PHP:
    PS Sorry for the messed up formatting...
     
    T0PS3O, Feb 9, 2005 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    $sql_data_array['purchase_without_account'] = '1';
    PHP:
     
    digitalpoint, Feb 9, 2005 IP
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Shawn!
     
    T0PS3O, Feb 9, 2005 IP
  4. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    PS Does the array order have to match the DB field order or does the DB field header simply have to match the array key in order to work OK?

    Or does it depend on the db entry function?

    This is the function:

      54    function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
      55      reset($data);
      56      if ($action == 'insert') {
      57        $query = 'insert into ' . $table . ' (';
      58        while (list($columns, ) = each($data)) {
      59          $query .= $columns . ', ';
      60        }
      61        $query = substr($query, 0, -2) . ') values (';
      62        reset($data);
      63        while (list(, $value) = each($data)) {
      64          switch ((string)$value) {
      65            case 'now()':
      66              $query .= 'now(), ';
      67              break;
      68            case 'null':
      69              $query .= 'null, ';
      70              break;
      71            default:
      72              $query .= '\'' . tep_db_input($value) . '\', ';
      73              break;
      74          }
      75        }
      76        $query = substr($query, 0, -2) . ')';
      77      } elseif ($action == 'update') {
      78        $query = 'update ' . $table . ' set ';
      79        while (list($columns, $value) = each($data)) {
      80          switch ((string)$value) {
      81            case 'now()':
      82              $query .= $columns . ' = now(), ';
      83              break;
      84            case 'null':
      85              $query .= $columns .= ' = null, ';
      86              break;
      87            default:
      88              $query .= $columns . ' = \'' . tep_db_input($value) . '\', ';
      89              break;
      90          }
      91        }
      92        $query = substr($query, 0, -2) . ' where ' . $parameters;
      93      }
      94  
      95      return tep_db_query($query, $link);
      96    }
    PHP:
     
    T0PS3O, Feb 9, 2005 IP