0

I want to add "max=<?php echo $row_select['max_price'] in hyperlink below, so that when the link's clicked, I can get both min and max price. Please advise how should the code be. Thank you.

Code in page 1

<a href="page2.php? min=<?php echo $row_select['min_price']; ?>">Price</a></td>

In page 2, my code to get min_price is as follows. It works. But I need to bring in max_price from page 1 as well.

$min_price = $_GET['min_price'];
<h2><?php echo $min_price; ?></h2>
0

3 Answers 3

2

please try code below:

<a href="page2.php?min_price=<?php echo $row_select['min_price']; ?>&max_price=<?php echo $row_select['max_price']; ?>">Price</a></td>


$min_price = $_GET['min_price'];
$max_price = $_GET['max_price'];
<h2><?php echo $min_price; ?></h2>
<h2><?php echo $max_price; ?></h2>
Sign up to request clarification or add additional context in comments.

Comments

1

Separate multiple query parameters with &.

<a href="page2.php?min=<?php echo $row_select['min_price']; ?>&max=<?php echo $row_select['max_price']; ?>">Price</a></td>

Comments

0
// Always use urlencode for query string values
<a href="page2.php?min=<?=urlencode($row_select['min_price'])?>&max=<?=urlencode($row_select['max_price'])?>">Price</a></td>

Or:

// http_build_query doesn't require urlencode (it encodes values automatically)
<a href="page2.php?<?=http_build_query([
    'min' => $row_select['min_price'],
    'max' => $row_select['max_price'],
])?>">Price</a></td>

And for reading:

<?php
// Use ?? to prevent "variable is undefined" error (operator ?? is available since php 7.0)
$min_price = $_GET['min_price'] ?? 0;
$max_price = $_GET['max_price'] ?? 0;
?>

// Always use htmlspecialchars to prevent XSS attack
<h2><?=htmlspecialchars($min_price)?>, <?=htmlspecialchars($max_price)?></h2>

1 Comment

Top two answers worked so I didn't try yours. But still want to thank you for your detailed explaination.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.