Log in

View Full Version : Search by Page ID



eminaymuzik
04-22-2009, 12:24 AM
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?

bluewalrus
04-22-2009, 02:15 AM
Is the formatting of the address always the same like yoursite.com/photo?ID=1123

eminaymuzik
04-23-2009, 08:30 PM
Yes, its always the same URL followed by a file ID. the URL does not changed!

Any help?

forum_amnesiac
04-24-2009, 08:11 AM
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.

eminaymuzik
04-25-2009, 12:48 AM
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?

Schmoopy
04-25-2009, 01:26 AM
Once you've made the necessary search box / form etc use this 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.