Passing Multiple Variables to Another Page in Url

Passing multiple variables to another page in url

Use the ampersand & to glue variables together:

$url = "http://localhost/main.php?email=$email_address&event_id=$event_id";
// ^ start of vars ^next var

Assigning multiple variables in one URL (Javascript)

The problem isn't with the function parameters, it's that only the first location.replace() has any effect, since it redirects and the JavaScript on this page stops running.

Assuming delete.php accepts multiple parameters, put them both in the same URL.

function deletefn(sku,part){
location.assign(`delete.php?prosku=${sku}&partx=${part}`);
}

Passing multiple variables between pages and using them

You can put as many values as you like on the query string. (Though as query strings get very long the web server would eventually impose a limit.) Here you simply append one key/value pair:

Response.Redirect("Results.aspx?cblvalues=" + cblvalues);

Just use a & to separate additional key/value pairs:

Response.Redirect("Results.aspx?cblvalues=" + cblvalues + "&moreValue=" + moreValues);

If you do get to the point where the query string becomes absurdly long and you basically have a lot of data to pass to the next page, then you'd be looking at other ways of doing this. A simple alternative may be to store the values in session state, redirect the user, then pull the values from session state. Something as simple as this:

Session["cblvalues"] = cblvalues;
Session["moreValues"] = moreValues;
Response.Redirect("Results.aspx");

Then in Results.aspx you can get the values:

var cblValues = Session["cblvalues"];
// etc.

You might also clear the session values once you get them, if the session doesn't need to keep carrying them:

Session.Remove("cblvalues");

How can i pass multiple value another page in URL


update.php?del=$id?name=$loginname

to

update.php?del=$id&name=$loginname

The first parameter is marked by ?, all following parameters are seperated by &

How to pass multiple variables in a href?

You should use the http_build_query() function, as it was designed for this:

$data = array(
'foo' => 'bar',
'baz' => 'boom',
'cow' => 'milk',
'php' => 'hypertext processor'
);

and then:

$base_url = 'https://my-website.com/';
$query_params = http_build_query($data);
$link = $base_url . '?' . $query_params;

echo '<a href = "' . $link . '">link text</a>';

Result:

<a href = "https://my-website.com/?foo=bar&baz=boom&cow=milk&php=hypertext+processor">link text</a>


Related Topics



Leave a reply



Submit