Jump to content
Larry Ullman's Book Forums

Sending Values To A Script - Url Parameters, Multiple Values For The Same Name

Recommended Posts

Sending values to a script (chapter 9), we are using hidden form fields and URL parameters.


What if I want to pass more values for one parameter? (not "name1=value1&name2=value2", rather "name1" having "value1" and "value2"). In the hidden form element I guess we define the element's value as an array. I am more interested in the URL situation, what will work best.


Is it safer to use numeric values as parameters or strings will be just fine?

Link to comment
Share on other sites

If you have an array with multiple values, it's best to split those values into multiple parameters in the URL.

You could, of course, pass all the values using one parameter, but that would require you to provide some sort of delimiter and split the string up on the PHP receiving end, which is just a waste.


One parameter per value is best. You can easily use a foreach loop, etc. to go through each value in the array and construct the parameters list for the URL.

  • Upvote 1
Link to comment
Share on other sites

Hi Hartley, thank you for your reply. The thing is that the number of values is variable and doing something to generate a unique name requires the same effort. I am interested in the best practices here, otherwise I assume it may be done either way. I am also interested if having the value of the parameter of numeric value is an advantage or not. I am guessing it is easier to use numbers; on the other hand if the database has a look up table to restrict the input to predefined values and this values are string I assume it is equally safe, the advantage being that it has meaning and one don't have to do any extra effort to interpret what the numeric value means. Now I do not have enough experience to decide.

Link to comment
Share on other sites

The difference between interpreting a number versus a string is so minor that you will never notice it. It'd probably take (literally) billions of operations with numbers versus strings before you'd even see a difference, so I wouldn't worry about that.

Send whatever values are most convenient for you.


As for best practices, while I don't have a source to quote at the moment, I can almost guarantee you that one value per parameter is the recommended course of action.

Beyond that, if you want to do your own thing, that's fine, but I think one value per parameter is the safest, easiest and least prone to human error.


If you'd like to give more specifics about your site, then maybe I could help more, but otherwise, there's not much else I can say.

Thanks for the inquiries though.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...