Results 1 to 6 of 6

Thread: Search by Page ID

  1. #1
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Search by Page ID

    Hi there everyone,

    I am looking for a code where a visitor is able to type in a file or page ID number in a box, and when they hit go the code will automatically take tem to "mysite.com/The code they typed in"

    Any help?

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Is the formatting of the address always the same like yoursite.com/photo?ID=1123
    Last edited by Snookerman; 04-22-2009 at 05:39 AM. Reason: removed link

  3. #3
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes, its always the same URL followed by a file ID. the URL does not changed!

    Any help?

  4. #4
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Is the page list static, ie always the same pages.

    If so you could present the options as part of a SELECT input type, saves your visitors from having to type anything

    It would then be possible to open the selected page using window.open in Javacript.

  5. #5
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well this is from my business employees, and there are over 5,000 documents. we reffer to those docs by ID number, so it would be easier if we had a search box that if they type in the Doc ID it would take them straight to it.

    Any help?

  6. #6
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Once you've made the necessary search box / form etc use this code:

    PHP Code:
    <?php

    // Let's say the only thing passed to the PHP code is the ID

    $id mysql_real_escape_string($_POST['id']); // Make safe for query

    $query mysql_query("SELECT * FROM photoids WHERE `id` = $id");

    if(!
    $query
    die(
    'Unable to execute query: ' mysql_error());

    if(!
    mysql_num_rows($query))
    die(
    'The ID you were looking for does not exist');

    // If it makes it this far then the ID does exist so we redirect to the appropriate page


    header("Location: mysite.com/photo?id=$id");

    ?>
    Hope this works for you

    Edit: I imagined that you'd have some sort of database, because there's not much point in having a search function if there're no records.

Bookmarks

Posting Permissions

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