Jump to content

Recommended Posts

Hi Guys,

 

Been at this for ages now i can't figure out how to do this, i have a function:

 

function:

 

function billing_payment_string($cusID, $ip, $referrer)
{

$q = "SELECT * FROM `fhp_orders` WHERE `customer_id`='$cusID'";
$r = mysql_query($q) or die (mysql_error());

while ($a = mysql_fetch_array($r))
{
//{

$pID = $a['product_id'];
$pQT = $a['quantity'];
//print "The product id is: ". $pID; . "And the quantity is: " . $pQT . "<br>";
//$test = array("$pID"=>"$pQT");
//print $pID;
}

//print_r($test);

$parameters = array('ip'=>'92.xxx.xx.xxx',
                     'sid'=>'9fe512105552ebfe963a98684a8daaa0',
                     'lang'=>'us',
                     'shipping_method_id'=>'1',
                     'wm'=>'3000',
                     'tr'=>'8027',
                     'pr'=>'11',
                     'site_id'=>'8027',
                     'nocustom'=>'',
                     'host'=>'site.com',
                     'referrer'=>'http://www.site.com/checkout.php',
                     'query'=>'',
                     'free_ship_method_id'=>'0',
                     'usa_euros'=>'0',
                     'use_pounds'=>'0',
                     'tmpl'=>'157',
                     'currency'=>'USD',
                     'version'=>'2.50',
                     
                     '3456'='4'
                     
                    );
                    
                    //print "<pre>";
                    //print_r($parameters);
                    //print "</pre>";
                    
                    // Serialize the string
                    //$stringSerialized = serialize($parameters);
                    
                    // Return the string for use...
                    return $parameters;
   
}

 

The query at the top of the function gets me product_id and quantity data of all the orders in the customers cart, i need to loop the data somehow inside the parameters array to look like:

 

'2346'=>'2',

'6742'=>'4',

etc

 

i tried putting the query inside the array but the script came up a blank page with no errors printed to screen, is there a better way to loop out the data to go inside the array?

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/184113-looping-data-inside-array/
Share on other sites

To add the product_id and quantity to your $parameters array you could do it like this

// define the array first
$parameters = array('ip'=>'92.xxx.xx.xxx',
                     'sid'=>'9fe512105552ebfe963a98684a8daaa0',
                     'lang'=>'us',
                     'shipping_method_id'=>'1',
                     'wm'=>'3000',
                     'tr'=>'8027',
                     'pr'=>'11',
                     'site_id'=>'8027',
                     'nocustom'=>'',
                     'host'=>'site.com',
                     'referrer'=>'http://www.site.com/checkout.php',
                     'query'=>'',
                     'free_ship_method_id'=>'0',
                     'usa_euros'=>'0',
                     'use_pounds'=>'0',
                     'tmpl'=>'157',
                     'currency'=>'USD',
                     'version'=>'2.50',
                     
                     '3456'='4'
                     
                    );

// query the database
$q = "SELECT * FROM `fhp_orders` WHERE `customer_id`='$cusID'";
$r = mysql_query($q) or die (mysql_error());
while ($a = mysql_fetch_array($r))
{
      // here the product id and quantity will be added to the array
      $parameters[ $a['product_id'] ] = $a['quantity'];
}

echo "<pre>".print_r($parameters, true)."</pre>";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.