Stan007 Posted January 9, 2020 Share Posted January 9, 2020 this is what i want in the url http://localhost/board/italian.php?page=2&country=italian when this link is clicked echo "<a href='?page=".($page_number + 1)." ".(&)." country=".($cleaned_current_page_country)."'>Next</a>"; but i keep getting this error: Parse error: syntax error, unexpected '&' in C:\xampp\htdocs\board\includes\menuboard_main_display.php on line 105 appreciate any help Quote Link to comment https://forums.phpfreaks.com/topic/309813-query-string-problem-is-whooping-my-behindhelp-please/ Share on other sites More sharing options...
ginerjm Posted January 10, 2020 Share Posted January 10, 2020 Change ." ".(& to .' '.(& and why do you wrap things in parens? $page_number++; echo " <a href='?page=$page_number&country=$cleaned_current_page_country'>Next </a>"; Note that I incremented the page num before the href Quote Link to comment https://forums.phpfreaks.com/topic/309813-query-string-problem-is-whooping-my-behindhelp-please/#findComment-1573234 Share on other sites More sharing options...
mac_gyver Posted January 10, 2020 Share Posted January 10, 2020 you should use http_build_query() when building the query string part of urls (it automatically urlencodes the values for you.) you should start with a copy of any existing $_GET parameters (before the start of you loop), so that your code only modifies the one(s) they are responsible for. you should use & as the separator in links. Quote Link to comment https://forums.phpfreaks.com/topic/309813-query-string-problem-is-whooping-my-behindhelp-please/#findComment-1573235 Share on other sites More sharing options...
Phi11W Posted January 10, 2020 Share Posted January 10, 2020 Remember that you're constructing a PHP string that just happens to contain some HTML markup that a web browser can make sense of. Nothing magical is going to happen to the way PHO does that building just because you're building "HTML" (or "SQL"). You must follow PHP Rules for constructing strings and having that "loose" ampersand floating around in the middle, whether or not it's wrapped in braces, just won't work. How about something more like this: printf( '<a href='?page=%d&country=%s'>%s</a>', $page_number + 1, $cleaned_current_page_country, 'Next' ); Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/309813-query-string-problem-is-whooping-my-behindhelp-please/#findComment-1573251 Share on other sites More sharing options...
Barand Posted January 10, 2020 Share Posted January 10, 2020 @mac_gyver gave the correct way to do it - http_build_query() EG $url = 'http://localhost/board/italian.php'; $data = [ 'page' => 2, 'country' => 'italian', 'comment' => 'this is a (simple) comment' ]; $qstr = http_build_query($data); $url .= '?' . $qstr; echo $url; //--> http://localhost/board/italian.php?page=2&country=italian&comment=this+is+a+%28simple%29+comment Note the encoding of the query string 1 Quote Link to comment https://forums.phpfreaks.com/topic/309813-query-string-problem-is-whooping-my-behindhelp-please/#findComment-1573257 Share on other sites More sharing options...
Stan007 Posted January 11, 2020 Author Share Posted January 11, 2020 Guys i am so thankful for all the help and support, i am overwhelmed. I will try every idea suggested about and get back to you guys......Many thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/309813-query-string-problem-is-whooping-my-behindhelp-please/#findComment-1573336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.