URL parameters are being built (into the $url variable) based on user input values, like this:
$query = trim($_GET["Query"]);
if (!empty($query)) {
$url = "results.php?";
$url .= "&Query=$query";
}
$store = $_GET["Store"];
if (!empty($store)) {
$url .= "&Store=$store";
}
These URL parameters (built into the $url variable) will be used to parse an XML document. Then ultimately search results will be displayed.
<product category="Tablet">
<name>ipad-1</name>
<store>Best Buy</store> // problem will later occur when store element has two words
</product>
<product category="Tablet">
<name>ipad-2</name>
<store>Amazon</store>
</product>
Multiple pages of search results are produced, and the page number links are created here.
for($i=0; $i<$searchResultsFound; $i++) {
if ($i == $a_condition) {
//This array below is where the probably likely is
$pageNumberLinks[] = "<a href=".$url."&firstSearchResult=".$firstSearchResultValue."&lastSearchResult=".$lastSearchResultValue.">".$pageNumberLink_i . "</a>";
}}
The page number links are displayed using this foreach loop.
foreach ($pageNumberLinks as $PageNumberLinks) {
echo $PageNumberLinks . " ";
}
The page number links are working fine when the store parameter (pulled from the XML element named 'store') have only one word (IE Amazon), and the URL in the address bar looks like this:
results.php?&Query=ipad&store=Amazon&firstSearchResult=10&lastSearchResult=20
However, when the store parameter has two words (IE Best Buy), the URL only displays the first word 'Best' and cuts off the remainder of the URL in the address bar, and looks like this:
results.php?&Query=ipad&store=Best
And the source code looks like this:
<a href=results.php?&Query=ipad&store=Best&firstSearchResult=10&lastSearchResult=20>2</a>
My guess is that the page number links are not coded correctly when inserted into the array in the for loop above. Does anyone notice anything coded incorrectly here:
$pageNumberLinks[] = "<a href=".$url."&firstSearchResult=".$firstSearchResultValue."&lastSearchResult=".$lastSearchResultValue.">".$pageNumberLink_i . "</a>";
As a side note, the URL works fine when coded like this:
<a href="<?php echo $url; ?>&Store=<?php echo $store; ?>">Anchor text</a>