We help IT Professionals succeed at work.

Passing multiple values in URL

Fernanditos asked
Last Modified: 2013-12-13

I have list of Artists on my table database.

Artist table has `id_usr`, `Intrument_ID`, 'name_usr'

I want to list artist passing the Instruments ID to the query, but I need to pass these ids in the URL

for example, I want to list all Guitar players and violin players, I need to do something like:


that would return all artist where Instrument_ID in ($url)

How to do this?

Watch Question

You need to make sure that you name the fieldname as an array.  

<input type=checkbox name="Instrument_ID[]" value="1" />
<input type=checkbox name="Instrument_ID[]" value="2" />
<input type=checkbox name="Instrument_ID[]" value="3" />

$Instruments= join(",", $Instrument_ID);
I would recommend storing the data in an array, then call the serialize command on the variable, then pass the serialized variable in the URL.


You need to make sure that you name the fieldname as an array.  

in your form,
<input type=checkbox name="Instrument_ID[]" value="1" />
<input type=checkbox name="Instrument_ID[]" value="2" />
<input type=checkbox name="Instrument_ID[]" value="3" />

on the next step to get the id's
$Instruments= join(",", $_POST['Instrument_ID']);

Sorry forgot the $_POST in my first entry.


Sorry, I dont understand, I am talking about passing the ids via URL. How to do it ?
try following example it is important that your are using , commas to separate instruments ids otherwise IN keyword will not work in WHERE clause of query

// do mysql connection with mysql_connect() and mysql_select_db

$instruments = $_GET['Instrument_ID'];

$query = "SELECT * FROM artists WHERE Instrument_ID IN ($instruments)";
$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result)) { 
  echo "<tr>\n";
  echo "<td>".$row['id_usr']."</td>\n";
  echo "<td>".$row['id_name_usr']."</td>\n";
  echo "<td>".$row['Instrument_ID']."</td>\n";
  // and so on for other fields
  echo "</tr>\n";

Open in new window

Hi Fernanditos,

What rstjohn is telling you is correct if you need a page where a user can select a number of instruments to search for and when they click submit the page that opens would read that list and display the data from your database.

I don't know what your current experience is with html forms so this is more of a complete example. In the form on your page, set the 'action' equal to the name of the page that will do your search and display the results. Set the 'method' to "get" so that when the form is submitted the values will be passed in the URL (see attached code snippet).

In your search results page, use the code provided above by nasirbest.
//in your search page
<form action="yoursearchresultspage.php" method="get">
  <input type="checkbox" name="Instrument_ID[]" value="1"/>&nbsp;<label>Cello</label><br/>
  <input type="checkbox" name="Instrument_ID[]" value="2"/>&nbsp;<label>Guitar</label><br/>
  <input type="checkbox" name="Instrument_ID[]" value="3"/>&nbsp;<label>Piano</label><br/>
  <input type="checkbox" name="Instrument_ID[]" value="4"/>&nbsp;<label>Violin</label><br/>
  <input type="submit" value="Search"/>

Open in new window

Unlock this solution and get a sample of our free trial.
(No credit card required)
Dang, sorry - I had commented out the actual query action while I was testing. Just alter line 14 to look like this:

$result = mysql_query($query);

Open in new window

And I forgot to close the <pre> tag on line 26. Haste makes waste...

I've only briefly read the top post.

But I would have the URL contain the instrument ID, then use a query to select all users who play that instrument.

This, rather than trying to build a string on submit, without some sort of forward to the URL after the original query i've just mentioned! O_o

Bit of sensible logic in my mind!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.