Page 1 of 1

MySQL query is used as page title

Posted: Wed Jan 11, 2012 4:43 pm
by Alcaeus
Many sites, such as online dictionaries, will often generate pages with the name of your search (or the nearest valid word) in the address bar.

For example, if I search for "elephant" on dictionary.reference.com then I am taken to a page called dictionary.reference.com/browse/elephant which contains all the information about the word elephant. If I bookmark that page I can head back to the elephant entry any time I like.

My question is how do I use MySQL search results as the titles of pages that I generate?

Many thanks! :D

Re: MySQL query is used as page title

Posted: Wed Jan 11, 2012 5:08 pm
by twinedev
Well, looking at the source of the page, you can see that when you click on the "Search", it is firing of Javascript function formcheck() (and the source to this is also viewable when you do view source.

this function is what ends up taking you to /browse/(searchterm).

I'm not sure what you are asking about the page titles... I don't think it is using mysql to generate the title tag, as no matter what I type in , it shows up in the title.

Now for how to handling the actual URL, you could do something like the following as an .htaccess file:

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ /index.php?cmd=$1&term=$2 [L]
</IfModule>
(I'm not the best at rewrite rules without testing them, so that may not be exact above), Gist of it would be that any request to the server that is not calling an actual file or directory, and it matches the layout of /whatever/whatever (ie /browse/elephant ), it will actually feed index.php?cmd=browse&term=elephant.

-Greg