0

How can i change the URL using PHP, I asked this question before but i didn't receive any answer . so this is my problem i want to add a pagination to my index page ,but in index page i have some icons that's filter some products , so the URL can be like that

www.mywebsite.com?id=66

so the problem is when i click on next (pagination) the URL instead of this

www.mywebsite.com?id=66&page=2

i get this

www.mywebsite.com?page=2

so my question is how can i add that parm the URL without removing the existing one using PHP because i tried with JavaScript but i didn't success .

1
  • php outputs whatever you tell it to. it doesn't know what html is, nor does it care. if you want a url's query parameters to be preserved when PHP outputs an <a> link, then you have to put them in there yourself. Commented Sep 17, 2014 at 19:31

1 Answer 1

1

I think you want to use http_build_query

Example:

http_build_query(array_merge($_GET, array('newVariable'=>'someValue')))

Also - possible duplicate of Manipulate a url string by adding GET parameters

Sign up to request clarification or add additional context in comments.

2 Comments

how can i make this code work ** if ($page > 1) $pagination.= "<li><a href='{$url}page={$prev}'>{$prevlabel}</a></li>"; **
I don't know what values those variables have, what the implementation is, or an explanation of how it is not working. I can't read your mind. It looks like you're generating a string from a couple different variables, under the condition $page, which I assume is an integer, is greater than 1. Where are you rendering it? So little information. Here's an article on PHP debugging I think you could benefit from: blog.teamtreehouse.com/how-to-debug-in-php

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.