Search the Community
Showing results for tags 'implode'.
-
I have used this command before and cannot remember the name or how to deploy it.. sorta like implode but different.. what it does is take an associative array and makes individual variables out of the array like this. $str = arrray("dog->catkiller", "house->placetolive:) and when applied results in the following. $dog = "catkiller"; $house = "placetolive"; Can anyone help me with this.. I need the command name and a sample of its use..
-
I have two questions relating to each other which are regarding - both function __autoload and adding products to a class? Code for an autoload function (please see code #1), the output prints - but also gives an error message? Moreover, I also receive the notification in my php editor "class 'ooo' not found"? If I may ask a silly question I have noticed some autoload fucctions have implode and explode - how would I write one of these? The output and error: My Antonia: Willa Cather (5.99) Fatal error: Class 'ooo' not found in C:\ Code#1: <?php // we've writen this code where we need function __autoload($classname) { $filename = "./". $classname .".php"; include_once($filename); } // we've called a class *** $obj = new ooo(); ?> ------------------------------------------------------------------------------------------------------------------------------ How would I add more products to this product class? code#2: <?php class shopProduct { public $title; protected $producer = []; public $price; public function __construct($title, $producerName1, $producerName2, $price) { $this->title = $title; $this->producer[] = $producerName1; $this->producer[] = $producerName2; $this->price = $price; } public function getProducer() { return implode(' ', $this->producer); } } class ShopProductWriter { public function write ($shopProduct) { $str = "{$shopProduct ->title}: " . $shopProduct -> getProducer() . " ({$shopProduct -> price})\n"; print $str; } } $product1 = new ShopProduct("My Antonia", "Willa", "Cather", 5.99); $writer = new ShopProductWriter(); $writer -> write($product1); ?>
-
Hello Every one Please see my code <?php include ("includes/config.php"); $afurl = $_SERVER['REQUEST_URI']; $afurl = preg_replace('/\/+/', '', $afurl); $afurl = preg_replace('/\;+/', '', $afurl); $afurl = preg_replace('/\&+/', '', $afurl); $afurl = preg_replace('/\#+/', '', $afurl); $afurl = preg_replace('/\|+/', '', $afurl); $afurl = preg_replace('/\@+/', '', $afurl); $afurl = preg_replace('/\%5B+/', '', $afurl); $afurl = preg_replace('/\%5D+/', '', $afurl); $afurl = preg_replace('/\%27+/', '', $afurl); $afurl = preg_replace('/\%C2+/', '', $afurl); $afurl = preg_replace('/\%BB+/', '', $afurl); $afurl = preg_replace('/quot+/', '', $afurl); $afurl = preg_replace('/\%E2+/', '', $afurl); $afurl = preg_replace('/\%80+/', '', $afurl); $afurl = preg_replace('/\%93+/', '', $afurl); $afurl = preg_replace('/\$+/', 'c', $afurl); $afurl = preg_replace('/\"+/', '', $afurl); $afurl = preg_replace('/\?+/', '', $afurl); $afurl = preg_replace('/\.html+/', '', $afurl); $afurl = preg_replace('/\-+/', ' ', $afurl); $queryArray = explode(" ", $afurl); for ($i=0; $i< count($queryArray); $i++) { $keyworddd = mysql_real_escape_string($queryArray[$i]).","; echo $keyworddd; } ?> I Want Set $keyworddd at here: <meta name="keywords" content="$keyworddd"> Can anyone tell me how to do this please?
-
this is a code of a shopping cart i'm trying to make. the cart displays the products with: name, size, price, quantity and total. When checked out it saves on Mysql DB. So it saves like this: user_1 | pants | XL | 10 $ | 1 | 10 $ | user_1 | t-shirt | L | 5 $ | 2 | 10 $ | user_2 | sock s | 8 | 7 $ | 5 | 35 $ | it's creating new row for each product for the same user. But what i need is this: user_1 | pants, t-shirt | XL, L | 10, 5 $ | 1, 2 | 20 $ | user_2 | socks | 8 | 7 $ | 5 | 35 $ | user_3 | t-shirt, hat | M, S | 5, 10 $ | 1, 1 | 15 $ | for the same user he implodes the data in the column of the same row. code: $products_array[$i] = array("user" => $user, "product" => $name_product, "size" => $size, "price" => $price, "quantity" => $each_item['quantity'], "total" => $cartTotal); if (isset($_SESSION["cart_array"]) && count($products_array) > 0 && isset($_POST['addOrder'])) { foreach ($products_array as $product) { $user = $_SESSION["user"]; $name_product = $product['name_product']; $size = $product['size']; $price = $product['price']; $quantity = $product['quantity']; $cartTotal = $product['total']; $result = mysqli_query($dbc,"INSERT INTO shop (user, product, size, price, quantity, total, date) VALUES('$user','$name_product','$size','$price','$quantity','$cartTotal',now())"); header("location: shop_cart.php"); } } So i been googling arround, and found that what i need is a implode function. But my problem is where and how to set it right. I have tried some code already but it doesnt work. I dont want to flood the DB Table with multiple rows of the same purchase. Any other suggestions on what to do to achieve my goal is accepted. Appreciate your help. Thank you.
-
Hi There, My WordPress header.php is giving me some grief. It was working just fine until I went into theme options and tried to specify a new page to appear on the main menu. Then the main menu broke! I get this error message: Warning: implode() [function.implode]: Invalid arguments passed in/nfs/c05/h04/mnt/83132/domains/gwrobinson.com/html/wp/wp-content/themes/gwr/header.php on line 54 Can any of you far superior php experts out there help me figure out how to fix this error message?? Thank you!!! The line of code in question is as follows: <?php $top_pages = get_pages('sort_column=menu_order&include=' . implode(',', get_option('top_navigation', array()))); ?> [/code} The whole header.php file is [code] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> <title><?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?>: Energy Efficient homes for sale in Garison Way & Turnberry Lake</title> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> <?php wp_head(); ?> <!--[if lte IE 6]> <style type="text/css" media="screen"> #featured-home .holder .box { background-image: none; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='<?php bloginfo('stylesheet_directory'); ?>/images/featured-home-box.png', sizingMethod='scale'); bottom: -1px; /* height: 250px; /* emulate max-height in ie6 */ } </style> <script type="text/javascript" charset="utf-8"> var isIE6 = true; </script> <![endif]--> <script src="<?php bloginfo('stylesheet_directory'); ?>/js/cufon-yui.js" type="text/javascript" charset="utf-8"></script> <script src="<?php bloginfo('stylesheet_directory'); ?>/js/Trajan_Pro_400.font.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript" charset="utf-8"> jQuery(function ($) { Cufon.replace('h2, h3, h4'); Cufon.replace('h3 .featuredtitle'); Cufon.replace('span.hthree'); if (typeof isIE6 != "undefined") { var slides_box = $('#featured-home .holder .box'); if ($(slides_box).height() > 250) { $(slides_box).height(250); } var innerpagebox = $('.innerpagebox'); if ($(innerpagebox).height() < 188) { $(innerpagebox ).height(188); } } }); </script> </head> <body <?php body_class(); ?>> <div class="shell"> <div id="header"> <h1 id="logo" class="fl notext"><a href="<?php echo get_option('home'); ?>"><?php bloginfo('name'); ?></a></h1> <div class="header-right"> <?php $top_pages = get_pages('sort_column=menu_order&include=' . implode(',', get_option('top_navigation', array()))); ?> <div id="social"> <div id="facebook"><a href="http://www.facebook.com/pages/GW-Robinson-homes/344500372268786" rel="nofollow" title="Become our fan on Facebook!" onClick="window.open(this.href); return false"></a></div> <div id="twitter"><a href="https://twitter.com/#!/GWRobinsonHomes" rel="nofollow" title="Follow us on Twitter!" onClick="window.open(this.href); return false"></a></div> </div> <p> <?php $i = 1; foreach ($top_pages as $_p): ?> <a href="<?php echo get_permalink($_p->ID); ?>"><?php echo apply_filters('the_title', $_p->post_title); ?></a> <?php if ($i!==count($top_pages)): ?> | <?php endif ?> <?php $i++; endforeach ?> </p> <div id="navigation"> <ul> <?php wp_list_pages('title_li=&sort_column=menu_order&link_before=<span>&link_after=</span>&include=' . implode(',', get_option('header_navigation', array()))) ?> </ul> </div> </div> </div> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-40896628-1', 'gwrobinson.com'); ga('send', 'pageview'); </script> <div id="content">
-
I am getting this error message, "Warning: implode() [function.implode]: Invalid arguments passed in/home/sam139/public_html/_import/functions.php on line 235" and I have no idea where I'm going wrong. The code where the issue is occurring is <p class="bline"><strong>Cast: </strong> <?= implode("<br/>", $p['cast']); ?></p> Where am I going wrong? Any help is much appreciated!
-
I looking for a good tutorial that will cover arrays, from HTML forms to storing the data( serialize,unserialize, implode, explode)in mysql with php I need to create a from that will allow me to create an array from text field then submit to database and late allow me to editied and update that array So I have four basic tables one serving as main table that will hold 5 field of data plus three field set aside for arrays then I have 3 tables that will hold keys and reference for those array plus additional data objective : In my main table the fields array1 array2 and array3 are the one I need to insert the array data into. I need to be able to manipulate the data of the array completely from an HTML form or multiple forms create basic HTML forms and PHP code to process I must be able to pull a record, check to see if that is an in those field array then add some data if their is if not start a new array for that record create basic HTML forms and PHP code to process I must be able to view and delete part of the array as well create basic HTML forms and PHP code to process then pull a record that has array data in it, then create a query base on those array to pull data from other tables and create some basic calculation base on the original record and the data that you reference in the other tables ( tables array1 array2 and array3 )create basic HTML forms and PHP code to process To help paint you better picture I am attaching below some sample tables and data I know that the data is not optimize but that is on purpose ok let say that this is( id) 2 in main 2 11 12 12 15 18 ('MOPQY4IV','9QR4TH7K','NZ1O45B0','1XUUU5D4','J94RVSNY')NULL NULL this array would be reference in table array1 'MOPQY4IV','9QR4TH7K','NZ1O45B0','1XUUU5D4','J94RVSNY' So in PHP I need to create a for loop that would take the value of this array and pull the data from table array1 I don't think the foreign key would work as this is not normalize database since other (id) in main could reference the same keys in array1 so I believe it be a many to many relation (id)3 could look some like this 3 10 16 12 17 14 ('MOPQY4IV','9QR4TH7K','JAM39TXN',)NULL NULL some of the array value are the same as in (id) 2 Thank You Antonio CREATE TABLE IF NOT EXISTS `array1` ( `id` int(11) NOT NULL AUTO_INCREMENT, `arrayKey` varchar( NOT NULL, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; -- -- Dumping data for table `array1` -- INSERT INTO `array1` (`id`, `arrayKey`, `data1`, `data2`, `data3`, `data4`, `data5`) VALUES (1, 'MOPQY4IV', 0, 1, 0, 3, 2), (2, '9QR4TH7K', 2, 2, 0, 0, 2), (3, '8NBYRZ72', 2, 1, 3, 3, 3), (4, 'NZ1O45B0', 0, 2, 2, 3, 2), (5, 'Y7XPA7Q3', 0, 0, 1, 1, 2), (6, '1XUUU5D4', 1, 3, 2, 1, 2), (7, 'JVUI1KA6', 2, 1, 3, 3, 1), (8, 'J94RVSNY', 3, 2, 3, 1, 1), (9, 'NF9YSEF4', 2, 3, 0, 1, 3), (10, 'LFY81TBA', 1, 1, 1, 3, 1), (11, 'LZH9S2DE', 0, 3, 2, 0, 1), (12, '7XK4NF8M', 3, 1, 1, 2, 0), (13, 'JAM39TXN', 0, 0, 2, 2, 1); -- -------------------------------------------------------- -- -- Table structure for table `array2` -- CREATE TABLE IF NOT EXISTS `array2` ( `id` int(11) NOT NULL AUTO_INCREMENT, `arrayKey` varchar( NOT NULL, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; -- -- Dumping data for table `array2` -- INSERT INTO `array2` (`id`, `arrayKey`, `data1`, `data2`, `data3`, `data4`, `data5`) VALUES (1, 'BZGZX887', 1, 0, 0, 0, 3), (2, 'WW7JG2WI', 3, 1, 0, 2, 0), (3, 'U1UAK4Z7', 0, 2, 2, 3, 0), (4, 'L1ETC8VM', 1, 3, 3, 3, 3), (5, 'RYPO75Y6', 3, 3, 0, 1, 0), (6, 'O9XKS4B0', 2, 2, 2, 2, 0), (7, 'A1W8VD5M', 1, 1, 0, 3, 3), (8, '4EH4IUBF', 1, 3, 3, 2, 0), (9, '2YV7VJML', 0, 2, 0, 1, 1), (10, '1V9TPRT8', 1, 2, 3, 3, 1), (11, '6XC0QJPB', 1, 2, 2, 3, 3), (12, 'JWX4SG1M', 2, 2, 3, 1, 0), (13, '60UBRIB2', 0, 0, 2, 2, 0); -- -------------------------------------------------------- -- -- Table structure for table `array3` -- CREATE TABLE IF NOT EXISTS `array3` ( `id` int(11) NOT NULL AUTO_INCREMENT, `arrayKey` varchar( NOT NULL, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; -- -- Dumping data for table `array3` -- INSERT INTO `array3` (`id`, `arrayKey`, `data1`, `data2`, `data3`, `data4`, `data5`) VALUES (1, 'XW2R8FZV', 0, 2, 0, 2, 1), (2, 'U0UQ4XE0', 3, 3, 3, 2, 1), (3, 'DJZ0F72P', 0, 2, 0, 2, 1), (4, '58NZG2QT', 3, 0, 3, 1, 0), (5, '8X0MTA7C', 3, 3, 1, 3, 0), (6, '566JPHPO', 3, 1, 0, 2, 2), (7, '59FE3PVA', 3, 0, 2, 3, 1), (8, 'O87PI80J', 1, 2, 0, 3, 3), (9, 'J69OP30N', 1, 2, 0, 2, 2), (10, '4VCA5FA9', 2, 1, 1, 3, 3), (11, 'N6I82WQS', 2, 0, 3, 0, 2), (12, 'ZSNV3O7K', 0, 0, 2, 2, 3), (13, 'YE6E4RB0', 2, 2, 3, 1, 0); -- -------------------------------------------------------- -- -- Table structure for table `main` -- CREATE TABLE IF NOT EXISTS `main` ( `id` int(11) NOT NULL AUTO_INCREMENT, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, `array1` text, `array2` text, `array3` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ; -- -- Dumping data for table `main` -- INSERT INTO `main` (`id`, `data1`, `data2`, `data3`, `data4`, `data5`, `array1`, `array2`, `array3`) VALUES (1, 10, 11, 15, 14, 16, NULL, NULL, NULL), (2, 11, 12, 12, 15, 18, NULL, NULL, NULL), (3, 10, 16, 12, 17, 14, NULL, NULL, NULL), (4, 18, 10, 13, 16, 11, NULL, NULL, NULL), (5, 11, 10, 13, 9, 15, NULL, NULL, NULL), (6, 9, 18, 14, 17, 14, NULL, NULL, NULL), (7, 14, 18, 16, 13, 17, NULL, NULL, NULL), (8, 15, 16, 12, 17, 17, NULL, NULL, NULL), (9, 17, 16, 12, 14, 10, NULL, NULL, NULL), (10, 17, 14, 11, 9, 17, NULL, NULL, NULL), (11, 12, 18, 10, 13, 13, NULL, NULL, NULL), (12, 10, 12, 14, 14, 10, NULL, NULL, NULL), (13, 14, 14, 12, 17, 18, NULL, NULL, NULL), (14, 1, 1, 1, 1, 1, NULL, NULL, NULL), (15, 22, 22, 22, 22, 22, NULL, NULL, NULL), (16, 1, 1, 1, 1, 1, NULL, NULL, NULL);
-
Im having a bit of trouble with my script. I wrote the script originaly to run from one variable which i changed manualy, but now im trying to put the whole script inside a loop. The script is now running all the way through fine on the first loop, starting starting the second but getting stuck at the part with my implode. This is my script that is around the implode area. Bear in mind that this code snippet is from a very large script. $t=1; while ($t <= $bm) { $mn=${'m'.$t}; $mn2[$t]="$mn"; $t++; } // The is where the script runs to, and the error comes from the next few lines and the script stops running $implode=implode(',', $mn2); print $implode; $query2="SELECT * FROM artists WHERE id IN(".implode(',', $mn2).")"; $result2=mysql_query($query2) or die(mysql_error()); $i=0; $bm2=$bm-1; while ($i <= $bm2) { $id3=mysql_result($result2,$i,"id"); ${"id3$i"} = $id3; $s1=mysql_result($result2,$i,"s1"); ${"s1$i"} = $s1; $s2=mysql_result($result2,$i,"s2"); ${"s2$i"} = $s2; $sl1=mysql_result($result2,$i,"sl1"); ${"sl1$i"} = $sl1; $sl2=mysql_result($result2,$i,"sl2"); ${"sl2$i"} = $sl2; $i++; } And this is the error that im getting ,,,You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',,)' at line 1 Any help or point in the right direction would be amazing right no. Thanks Eric
-
Hey guys i've got a rookie question. How do i shuffle an array then display each number in the array using implode? Heres my code. $maximum_integer = strip_tags(trim($_REQUEST['maximum_integer'])); $range = range(0,$maximum_integer); $range_randomized[] = shuffle($range); $random_range_imploded = implode(', ', $range_randomized); print $random_range_imploded; it just keeps displaying '1'.... Thanks!
-
Hi thanks for reading my first post. I'm having trouble with a checkout form processor that is working but throwing WARNINGS that my sales team (and later direct customers) should not get. I am trying to grab customer cart information (one or more rows), grab it as an array, convert all to string, replace the double shipping (if it exists), and store it in final variable $prodfinal. Here is the code: // BTG Product Inserting Code $result_products = mysql_query("SELECT name, name2 FROM cart WHERE invoice_id=$invoice_id"); while($products[]= mysql_fetch_array($result_products,MYSQL_ASSOC)); $prod3=" "; foreach($products as $prod2) { $prod3.=" ".(implode(" ",$prod2)); } $prod2=(implode(" ",$products)); $prodfinal=str_replace('Shipping Shipping','& Shipping',$prod3); // BTG code end This code executes successfully but throws: Warning: implode() [function.implode]: Invalid arguments passed in /home1/beatth13/public_html/cms/customer_orders_list32.php on line 42 Warning: Cannot modify header information - headers already sent by (output started at /home1/beatth13/public_html/cms/customer_orders_list32.php:42) in /home1/beatth13/public_html/cms/customer_orders_list32.php on line 180 line 42 is the -- foreach($products as $prod2) { $prod3.=" ".(implode(" ",$prod2)); } I tested this code segment on its own php test page and it runs fine, no warnings... when I embed it in the larger form processing page the implode function...well...implodes. ALSO it throws the "output started" error from line 42 except I REALLY do not see where I am sending any output... It does not appear to me that I am sending any HTML output at this point but apparently I am wrong. Thank you in advance for your help! BTG