graham23s Posted December 5, 2009 Share Posted December 5, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/184113-looping-data-inside-array/ Share on other sites More sharing options...
wildteen88 Posted December 5, 2009 Share Posted December 5, 2009 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/184113-looping-data-inside-array/#findComment-972052 Share on other sites More sharing options...
graham23s Posted December 5, 2009 Author Share Posted December 5, 2009 Brilliant! works perfectly, thanks a ton WT. Graham Quote Link to comment https://forums.phpfreaks.com/topic/184113-looping-data-inside-array/#findComment-972054 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.