Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

Handling multiple inputs with same name

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
robjohnston
Asked:
robjohnston
  • 4
  • 4
1 Solution
 
a.marshCommented:
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
 
robjohnstonAuthor Commented:
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
 
a.marshCommented:
Are you using the implode() function?

e.g.

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

:o)

Ant
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
robjohnstonAuthor Commented:
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
 
robjohnstonAuthor Commented:
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
 
robjohnstonAuthor Commented:
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
 
a.marshCommented:
My pleasure. :o)

Ant
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now