Q: PHP URL Variable Appending Hoping this is a simple and easy question. I've seen multiple examples of, and know how to append variables to the URL (i.e. mydomain.com/index.php?id=1&stat=0), but my question is this:
If I have a page on my site that already has variables in the URL (i.e. mydomain.com/tickets.php?stat=Open), how can I append a page number to the end of that URL (i.e. mydomain.com/tickets.php?stat=Open&page=2). This is for pagination purposes of a table with values from my database, that includes a search and select function (select open, closed, or all tickets, and search for a specific ticket number).
I've done several searches with google, and came up dry, as most topics regarding this have you hardcode the url with variables from the get go, and not append them. I may just be using the wrong search parameters as well, and am not sure what to search for exactly.
Any help or insight on this would be greatly appreciated, thank you.
Please note I wish to do this solely in PHP, HTML, and MySQLi. I want to refrain from using javascript or ajax if possible for my clients that may have those features disabled on their browsers.

A: Using this way:--
<?php
    $domain = "mydomain.com";

    $page = "tickets.php?";


    $full_page_url = $domain.'/'.$page;

    $arr = array('stat' => 'Open', 'page' =>2); 

    $add= http_build_query($arr); 

    $correct_url = $full_page_url. $add;

    echo $correct_url;
 ?>


output:--mydomain.com/tickets.php?stat=Open&page=2


A: I would do it like this:
$page = 2;

$url = 'mydomain.com/tickets.php?stat=Open';

if( false !== strpos($url, '?')){
    //if url has a ? split it.
    $arr_url = explode('?', $url); 
    //convert query string to array, $array=['stat'=>'Open']
    parse_str($arr_url[1], $array);
    //add or replace page by array key
    $array['page'] = $page;
    //convert it back to a query string.
    $query = http_build_query($array);

   print_r($query);
}

Outputs
stat=Open&page=2

It's a simple matter of putting $query back with $arr_url[0]  I'll leave this up to you.  But I will give you a hint $arr_url[0].'?'.$query
The advantage here is that you don't have to worry about getting into a situation where you are adding page after page after page after...  
Like this:
 mydomain.com/tickets.php?stat=Open&page=1&page=2&page=3

You can't simply concatenate it onto the end of the url, and it's probably just as hard to remove it as it is to parse the query string.
As a side note, you could just use $_GET but where is the fun in that, as $_GET is the query string already parsed as an array ( so you could skip parse_str).  But it may not be on a request, such as if you were just building the link from a string. 
So I thought I would show it with parse_str to cover the "harder" case.  
One last thing if you are just building a bunch of urls all the same except the page part.  The obvious answer is to setup a base url and then just loop out the numbers.
 $url = 'mydomain.com/tickets.php?stat=Open';

 $pagedUrls = [];

 $numberPages = 10;

 for($i=1; $i<=$nubmerPages; $i++){
    $pagedUrls[] = $url.='&page='.$i;
 }

Or what have you for the number of pages.
It's really not that clear in your question exactly what you are trying to do..
Hope that helps.
