Solved

Handling multiple inputs with same name

Posted on 2002-07-02
8
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 15

Expert Comment

by:a.marsh
ID: 7124398
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
ID: 7124487
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
ID: 7124586
Are you using the implode() function?

e.g.

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

:o)

Ant
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:a.marsh
ID: 7124587
0
 
LVL 1

Author Comment

by:robjohnston
ID: 7124901
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
ID: 7125032
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
ID: 7192246
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
ID: 7192745
My pleasure. :o)

Ant
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
can i read my emails on lamp ftp 4 26
Wordpress Query 5 45
Google Dork query 7 66
how to use a foreach loop in heredoc used to send email via php 14 8
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 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