473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

problem with implode() function

45
Hi,
I am having a problem with implode() function in PHP.
whenever i am running my code it display an error like.

Warning: implode() [function.implode]: Bad arguments. in D:\xampp\htdocs\admin\addspecs.php on line 8

and my code is

Expand|Select|Wrap|Line Numbers
  1. $as = $_POST;
  2. $i=1;
  3. while($i<=16)
  4. {
  5. $ad = $as['txtRow'.$i];
  6. $aw = implode(",",$ad);
  7. $qw = "#".$aw;
  8. echo $qw;
  9. $i++;
  10. }
  11.  
what is the error in this code can anybody tell me.
Apr 9 '09 #1
6 2409
Dormilich
8,658 Expert Mod 8TB
the problem is that $ad is not an array (it's the value of a POST element). further you should call implode() outside the while-loop.

you can create arrays like
Expand|Select|Wrap|Line Numbers
  1. // repeat
  2. $array[] = $value;
  3. // or
  4. $array[$key] = $value;
or use some of the array functions
Apr 9 '09 #2
tokcy
45
hi,

still i am not getting the solution. and how we can put the implode to outside of the while loop because all the text field name are unique and i can take the value of text fields without while loop.
Apr 10 '09 #3
Dormilich
8,658 Expert Mod 8TB
what I wanted to say is, you need to change the code structure

Expand|Select|Wrap|Line Numbers
  1. while (…)
  2. {
  3.     // …
  4.     $array[] = $_POST[$key];
  5. }
  6. $string = implode(",", $array);
Apr 10 '09 #4
tokcy
45
Now its not giving an error, but when i am trying to print the value it showing only array like this:
Array,Array,Array,Array,Array,Array,Array,Array,Ar ray,Array,Array,Array,Array,Array,Array,Array,Arra y,Array

Expand|Select|Wrap|Line Numbers
  1. $i=0;
  2. while($i<=$count)
  3. {
  4. $arr[] = $_POST['txtRow'.$i];
  5. $i++;
  6. }
  7. $str = implode(",",$arr);
  8. echo $str;
  9.  
Apr 10 '09 #5
Dormilich
8,658 Expert Mod 8TB
looks like $_POST['txtRow'.$i] is an array. if you set error reporting to E_ALL you should get the according notices.
Apr 10 '09 #6
hsriat
1,654 Expert 1GB
I too think there's some problem with $_POST thingie itself. You should see what you are actually POST'ing to the page. Use
Expand|Select|Wrap|Line Numbers
  1. echo"<pre>"; print_r($_POST); echo "</pre>";
in the starting of the page. Then you can see what's going wrong.

Also, if you have to iterate through the POST'ed array anyhow, then you can just concat the POST variable instead of imploding it after converting it to another array.
Expand|Select|Wrap|Line Numbers
  1. while (condition) 
  2. {
  3.     $str .= $_POST[whatever];
  4.     //increment thing
  5. }
  6. echo $str;
Apr 10 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jeff | last post by:
Hello. Quick background as I dont wish to hog anyones time. I am a customer of a PHP/SQL programmer. A website that I had the programmer build for me is working great, with one exception. I...
2
by: DJ Craig | last post by:
I have 2-dimensional array with numeric indices for both dimensions, called $results, which contains the search results from a database. The first dimension contains the records, and the second...
11
by: Leszek | last post by:
Hi I' m trying convert a php array to a javascript array like this: var danevar1 = "<? print $dane1; ?>"; var danearray1= new Array(); danearray1 = danevar1.split(","); var suma1=0; for(var...
4
by: bb nicole | last post by:
BElow is my php code for candidate search, it have 4 criteria which is academic background, functional experience, preferred location and languages ability. but it show yhe blanks page.. Emm, is it...
18
by: NoWhereMan | last post by:
Maybe a stupid question. ------------------------- 1 ------------------------- $str = ''; for($i=0; $i<10; $i++) $str .= $i;
1
by: scatfly | last post by:
I have a set of values that were put into a form and am now using this to put into a database. this is my error: "Warning: implode() : Bad arguments. in /home/xxxxxx/public_html/login.php on line...
4
by: atyndall | last post by:
OK, this is the relevant portion script: <?php $username = '__'; // MySQL Database Username. $password = '__'; // MySQL Database Password. $server = '__'; // MySQL Database server (most...
30
by: Einstein30000 | last post by:
Hi, in one of my php-scripts is the following query (with an already open db-connection): $q = "INSERT INTO main (name, img, descr, from, size, format, cat, host, link, date) VALUES ('$name',...
5
by: swethak | last post by:
hi, i want to zip the folder using php. Any body plz help for that.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.