wkilc Posted August 20, 2010 Share Posted August 20, 2010 I tired something earlier, with no luck... so I'm taking a few steps back. I've been working this one complicated page for days... Here's what used to work: //the current URL $page_name = $_SERVER["REQUEST_URI"]; //remove any old limit from query before requesting a new limit $tmp = array(); foreach ($_GET as $fld => $val) if ($fld != 'limit') $tmp[] = $fld . '=' . $val; $page_name = $_SERVER['SCRIPT_NAME'] . '?' . implode('&',$tmp); //sets the number of records to be displayed on the page <form> <select name="link"> <option value="<? echo "$page_name" ?>&limit=25">25 records per page</option> <option value="<? echo "$page_name" ?>&limit=50">50 records per page</option> <option value="<? echo "$page_name" ?>&limit=100">100 records per page</option> </select> </form> This grabs the current URL, and clears the &limit= string before a new limit is introduced to avoid: www.example.com/test.php?sub=math[]&sub[]=science&limit=25&limit=50&limit=100 The problem, is that my URL is already querying an array: www.example.com/test.php?sub[]=math&sub[]=science So now, when I apply the form above to this URL set the new limit to 50 records per page the URL actually becomes: www.example.com/test.php?sub=Array&limit=50 Warning: Invalid argument supplied for foreach() ... on line 147 I guess I've broken the array? //line 147 echo "subject:<BR />"; if(!empty($_GET['sub'])) foreach($_GET['sub'] as $sub) { echo "$sub <BR />\n"; } ~Wayne Link to comment https://forums.phpfreaks.com/topic/211238-problem-with-arrays-in-url-query/ Share on other sites More sharing options...
sasa Posted August 20, 2010 Share Posted August 20, 2010 $page_name = $_SERVER["REQUEST_URI"]; $page_name = preg_replace('/&?limit=\d+/','',$page_name); Link to comment https://forums.phpfreaks.com/topic/211238-problem-with-arrays-in-url-query/#findComment-1101496 Share on other sites More sharing options...
wkilc Posted August 20, 2010 Author Share Posted August 20, 2010 THANK YOU!!!! I was trying to simplify for the purpose of posting... the problem now is... I've got more than one value: there's also &start= which tells it if we're on the first, second, third, etc.. of the displayed pages. The idea is that I want to clear the one I'm changing while keeping the other. www.example.com/test.php?sub=math[]&sub[]=science&limit=50&start=50 Can't do both like this, right? $page_name = $_SERVER["REQUEST_URI"]; $page_name = preg_replace('/&?limit=\d+/','',$page_name); $page_name = preg_replace('/&?start=\d+/','',$page_name); ~Wayne Link to comment https://forums.phpfreaks.com/topic/211238-problem-with-arrays-in-url-query/#findComment-1101504 Share on other sites More sharing options...
sasa Posted August 20, 2010 Share Posted August 20, 2010 yes if start is number Link to comment https://forums.phpfreaks.com/topic/211238-problem-with-arrays-in-url-query/#findComment-1101508 Share on other sites More sharing options...
wkilc Posted August 20, 2010 Author Share Posted August 20, 2010 $page_name = $_SERVER["REQUEST_URI"]; $page_name = preg_replace('/&?limit=\d+/','',$page_name); $page_name = preg_replace('/&?start=\d+/','',$page_name); This doesn't work for the &start= link comes out as "sub=Array" again. If I change it to this: $page_name = $_SERVER["REQUEST_URI"]; $page_name = preg_replace('/&?limit=\d+/','',$page_name); $page_name2 = preg_replace('/&?start=\d+/','',$page_name); Then it obviously doesn't flush &limit= anymore. I'm sorry... ~Wayne Link to comment https://forums.phpfreaks.com/topic/211238-problem-with-arrays-in-url-query/#findComment-1101514 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.