Solved

Handling multiple inputs with same name

Posted on 2002-07-02
8
195 Views
Last Modified: 2006-11-17
Hi folks.

I've got a page where people can choose several option such as hair colour. When the form is submitted the GET string looks like:

**.php?hair=blue&hair=green&hair=red

but is there a way I can get the the string to format like thus:

**.php?hair=blue,green,red

Currently I'm using an array[] then imploding it but I'd rather format the string in the way I want it first.

Cheers, Rob.
0
Comment
Question by:robjohnston
  • 4
  • 4
8 Comments
 
LVL 15

Expert Comment

by:a.marsh
Comment Utility
You could adjust things on the client side before it gets submitted to the PHP script using Javascript, but I would advise against that if at all possible.

My reason for that is that you have little control over the client compared to what you have over the server.

I would recommend leaving it so that PHP creates the string in the format you need.

Can I ask why you watnt to have it like that?

:o)

Ant
0
 
LVL 1

Author Comment

by:robjohnston
Comment Utility
Hi Ant.

I thought about java but it's too much effort for such a small thing.

To be honest I wanted it to do it this way because I thought that it was supposed to. Having seen something like it before I just assumed that's the way it worked and so I wrote some of the pages with that in mind.

Also the SQL statement I'm using looks something like:
SELECT * FROM table WHERE id IN (1,2,3,4)

Cheers, Rob.
0
 
LVL 15

Accepted Solution

by:
a.marsh earned 100 total points
Comment Utility
Are you using the implode() function?

e.g.

$query = "select * from table where id in (" . implode($hair) . ")";

:o)

Ant
0
 
LVL 15

Expert Comment

by:a.marsh
Comment Utility
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:robjohnston
Comment Utility
Hi.

Yup, I'm using the implode function. I found this page while I was pondering the problem:
http://www.devshed.com/Server_Side/PHP/DB_Basics/page6.html

So far so good really.

Thanks, Rob.
0
 
LVL 1

Author Comment

by:robjohnston
Comment Utility
Hi.

Yup, I'm using the implode function. I found this page while I was pondering the problem:
http://www.devshed.com/Server_Side/PHP/DB_Basics/page6.html

So far so good really.

Thanks, Rob.
0
 
LVL 1

Author Comment

by:robjohnston
Comment Utility
Hi Ant, sorry about the delay. I used your idea of the implode function.

Thanks for your time and effort and sorry again about the delay.

Cheers, Rob.
0
 
LVL 15

Expert Comment

by:a.marsh
Comment Utility
My pleasure. :o)

Ant
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now