Jump to content

Search field on web page


kurt.santo

Recommended Posts

Well, I guess the easiest method would be to store all the page data into the database and then search for it with the SQL LIKE operator.Another idea that come to mind is checking through all the files with PHP, but it takes more work.If you wanted something very easy, google offers customized seach bars for your site.

Link to comment
Share on other sites

Well, I guess the easiest method would be to store all the page data into the database and then search for it with the SQL LIKE operator.Another idea that come to mind is checking through all the files with PHP, but it takes more work.If you wanted something very easy, google offers customized seach bars for your site.
little curious about the Google search bar... could you give me the script? :)
Link to comment
Share on other sites

Well, I guess the easiest method would be to store all the page data into the database and then search for it with the SQL LIKE operator.Another idea that come to mind is checking through all the files with PHP, but it takes more work.If you wanted something very easy, google offers customized seach bars for your site.
Ingolme,What would I need to search for when I wanted to try the PHP file version? Would love to give it a go...Kurt
Link to comment
Share on other sites

Well, that's quite complicated, I'd need to spend some time coming up with a script to do that. In the end I think it's more worth to try other methods.Hmm, let me see how I'd do it.I'd first have all the pages in the same folder, use scandir() ( http://w3schools.com/php/func_directory_scandir.asp ) to return all the pages in that folder.Then I'd go through the files. Better than fopen() I'd use file_get_contents() ( http://w3schools.com/php/func_filesystem_f...et_contents.asp )For each file in the array of files:if(strstr($filestring, [string to be found]) !== FALSE) { // Change $filestring for the variable of the file string returned earlier with file_get_contents// write <a href="filename">File name</a> or do whatever you wanted when the result is found}Anyways, you'll have to develop that idea a bit further, I'm not going to make the full script myself since it would take me more time than it's worth.

Link to comment
Share on other sites

You could also, instead of having your content database-driven, simply periodically index the data (like a search engine) to a database table and search from that. So, you can have a non-database-driven site with database-driven search features.

Link to comment
Share on other sites

You could also, instead of having your content database-driven, simply periodically index the data (like a search engine) to a database table and search from that. So, you can have a non-database-driven site with database-driven search features.
Thank you for your opinions on that. I am a bit confused, always thought databases were THE thing to use in dynamic web development (I have not used them myself yet really)... Is it the delay in response or why would you always try to search for alternatives? But an online shop with many products surely should use database tables then?Kurt
Link to comment
Share on other sites

I think it's better, but personally I don't like to waste database tables for that.
"Waste" tables? Do you have a limit on how many tables you can have? Does your host charge you per table? If the best solution is to add a database table there's no problem with that, if that's the best tool for the job then that's what you do.
But an online shop with many products surely should use database tables then?
Any time you have a large amount of related data that needs to be stored, a relational database is probably the way to go. If the data is not related in any way, like if you just have a bunch of blocks of independent text that will get displayed on various pages, you can just as easily store that in something like a file. It might even be faster. But if the data has relations, constraints, rules, etc, the database management system is built specifically to manage those things while making the data available quickly. It would be a pain to try and enforce a "primary key" rule in a flat file structure, but a DBMS will take care of that for you, and much more. Any system where the data is being updated frequently will also need some sort of race condition checking to make sure two things aren't trying to update the same thing at the same time. A DBMS will also handle consistency and transaction atomicity, both of which are important in a system where many clients may be updating or changing the data all at once.Database management systems are built specifically to handle all of the behind-the-scenes things that need to take place that most people don't even know about because they've only ever used databases. If you build a large multi-user application where a lot of users are updating the data all at once and you use a file-based storage system for the data, you'll experience many of the problems that a DBMS solves pretty quickly.
Link to comment
Share on other sites

"Waste" tables? Do you have a limit on how many tables you can have? Does your host charge you per table? If the best solution is to add a database table there's no problem with that, if that's the best tool for the job then that's what you do.Any time you have a large amount of related data that needs to be stored, a relational database is probably the way to go. If the data is not related in any way, like if you just have a bunch of blocks of independent text that will get displayed on various pages, you can just as easily store that in something like a file. It might even be faster. But if the data has relations, constraints, rules, etc, the database management system is built specifically to manage those things while making the data available quickly. It would be a pain to try and enforce a "primary key" rule in a flat file structure, but a DBMS will take care of that for you, and much more. Any system where the data is being updated frequently will also need some sort of race condition checking to make sure two things aren't trying to update the same thing at the same time. A DBMS will also handle consistency and transaction atomicity, both of which are important in a system where many clients may be updating or changing the data all at once.Database management systems are built specifically to handle all of the behind-the-scenes things that need to take place that most people don't even know about because they've only ever used databases. If you build a large multi-user application where a lot of users are updating the data all at once and you use a file-based storage system for the data, you'll experience many of the problems that a DBMS solves pretty quickly.
justsomeguy,Thank you for your input! I am glad my assumptions were not completely incorrect;-) Will keep that in mind for any future project...Kurt
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...