Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Nov 2010
    Location
    Scotland
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Returning to a db page keeping the same search parameters

    I have a db page and when you leave the page to post selections on return you come back to the same id row you selected beacause I have this code on the select.php page (thx to Mattf and others)
    PHP Code:
    $back = isset($_GET['id']) ? '#' .intval($_GET ['id']) : '';
    header'Location: indexfull2.php'.$back ); 
    This is fine if the user hasn't input any search parameters, if they have made a search for 'beatles' they would return to the page at the id row they had selected but it would be within the entire database page rather than the search beatles page with 20 or so rows.
    So is there away to save the search parameters on exit from the db page and re select them on the way back, rather than selecting the entire db it normally does.
    The code

    PHP Code:
    $var = @$_GET['a'] ;
      
    $search1 = ($var);
          
      
    $var = @$_GET['b'] ;
      
    $search2 = ($var);
      
      
    $var = @$_GET['c'] ;
      
    $search3 = ($var);
      
      
    $var = @$_GET['d'] ;
      
    $search4 = ($var);
      
      
    $var = @$_GET['e'] ;
      
    $search5 = ($var);
      
      
    $var = @$_GET['f'] ;
      
    $search6 = ($var);
      
      
    $var = @$_GET['g'] ;
      
    $search7 = ($var);
        
      
    mysql_connect("localhost","root",""); 

      
    mysql_select_db("a2149809_MV") or die ("Unable to select database"); 
      
      
    $query "SELECT * FROM `music vidz` WHERE `Artist` LIKE \"%$search1%\" 
      AND `Title` LIKE \"%$search2%\" AND `Disc` LIKE \"%$search3%\" 
      AND `Era` LIKE \"%$search4%\" AND `Date Added` LIKE \"%$search5%\" 
      AND `AR` LIKE \"%$search6%\" AND `Quality` LIKE \"%$search7%\" order by `Artist`"

     
      
    $result=mysql_query($query);
      
    $num=mysql_num_rows($result);
      
      
    mysql_close(); 

  • #2
    New Coder
    Join Date
    Nov 2010
    Location
    Scotland
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can use this to retrieve the url
    PHP Code:
    $fulluri 'http://' $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
    Trying to use the search button to send this info to the select page by putting this href in the search button
    PHP Code:
    <a uri="<?php echo $fulluri.'" href="select.php?uri='.$fulluri.">
    but having no luck, I will then have to collect that on the select page, but not entirely sure how, anyone help?

  • #3
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Use sessions.

  • #4
    New Coder
    Join Date
    Nov 2010
    Location
    Scotland
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Matt does this code mean I have the session variable stored as this url, it does echo the right url but on the same page, obviously I want to retrieve it on another page

    PHP Code:
    <?php
    session_start
    ();
    $_SESSION =$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    ?>
    <?php
    echo "http://" .$_SESSION;
    ?>

  • #5
    New Coder
    Join Date
    Nov 2010
    Location
    Scotland
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Managed to do it

    db page
    PHP Code:
    session_start();
    $_SESSION['comeback'] = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
    select page
    PHP Code:
    session_start();
    $redirect $_SESSION['comeback'];



    $back = isset($_GET['id']) ? '#' .intval($_GET ['id']) : '';
    header'Location: http://'$redirect.$back); 
    Thanks for the tip Matt should I add anything to this code to make it proper?

  • #6
    New Coder
    Join Date
    Nov 2010
    Location
    Scotland
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Continuing from above does anyone know why this href would produce this

    PHP Code:
    session_start();
    $redirect $_SESSION['comeback']; 
    <form>
    <a href="<?php echo "$redirect" ?>" style="text-decoration:none">
    <input type="button" value="Back To The Database" /></a>
    </form>


    http://127.0.0.1/127.0.0.1/indexfull...d=&e=&f=&g=&h=

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    The wonders of HTTP. You'll have to do some parsing/cleaning of the SERVER vars. They won't always be giving you the exact output you expect.

  • #8
    New Coder
    Join Date
    Nov 2010
    Location
    Scotland
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thx for the reply,the echo seems ok, so isn't the problem in the href code?

    PHP Code:
    session_start();
    $redirect $_SESSION['comeback'];
    echo 
    $redirect
    outputs
    127.0.0.1/indexfull2.php?Submit=Search&a=beatles&b=&c=&d=&e=&f=&g=&h=

  • #9
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Make the URI absolute instead of relative.

    Code:
    $redirect = 'http://'.$_SESSION['comeback'];
    It won't prepend the current path then.

  • #10
    New Coder
    Join Date
    Nov 2010
    Location
    Scotland
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That did it Matt thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •