Jump to content

How do I add a search engine?


kanala

Recommended Posts

How do I add a search engine on my site. It is an html site and I want to make it like a shop where you can search keywords for a product, and a results page comes up with the found products. Does this have to be in php, if so is it possible to implant a separate php scripts page into html like you can do with css and js?

Link to comment
Share on other sites

You can use PHP/MySQL, but you don't have to use either of them if you don't want. PHP can be embedded inside HTML files, and the user will not see it.
That's pretty vague.If your products are stored in a database, you can build a PHP script that will search the database for certain keywords with a page to display the matches. If your site is just static HTML pages, I guess you could open each page and search through it, but it's not going to be that great of a search, the results will probably have some false positives. Almost all searching takes place in a database, it's much faster.As far as PHP being embedded in an HTML file, a PHP file is a text file that could contain some HTML code as well. When the PHP program on the server runs to execute the PHP code in the file, it looks for all PHP code, ignores all other code such as HTML, and processes the PHP code. In most cases the PHP code generates more HTML code. The user sees the result of the PHP running, so if the PHP outputted a bunch of HTML code the user viewing the page would see the HTML code that was produced, not the PHP code that produced it.
Link to comment
Share on other sites

I just found out that my server does not support SQL or PHP so is there a javascript of html way?
Sadly, no. You need some sort of server scripting to do the search. Javascript would be able to identify text on the current page alone, but that's it.
Link to comment
Share on other sites

Sadly, no. You need some sort of server scripting to do the search. Javascript would be able to identify text on the current page alone, but that's it.
OK i'll just make a long drop down list.Thanks anyway
Link to comment
Share on other sites

  • 4 weeks later...
are u using a free host? if so i can tell u a good one that allows these php etc and also has phpmyadmin and php sql etc so?
Ok I'v switched my host to a better one (paid). awardspace.com allows all php and other stuff. It also has a PHPMyAdmin program to help me make a database. Now I just need help making the search engine. And also is it possible to change the product names and descriptions to the names and descriptions in the database? E.g. so that if I need to edit a product description, I don't have to edit the html page, but just change the info in the database?My website is HTML based, www.takeawaydvds.com, you see each product takes at least 5-10 mins to add because I have to edit the HTML coding. And I need to put a search box onto the site.
Link to comment
Share on other sites

Make sure to at least get the basics of PHP/MySQL (they both provide a lot of info for both products at their official websites). Have PHP/MySQL, JavaScript, CSS, HTML/XHTML in different files and to embed them inside the HTML code with PHP include/require functions or the HTML embed tags for JS/CSS. You can create one file for the top of the page Logo/Navigation, the content, and one more for the bottom of the page for anything else you want to add.http://www.php.nethttp://www.mysql.com

Link to comment
Share on other sites

Make sure to at least get the basics of PHP/MySQL (they both provide a lot of info for both products at their official websites). Have PHP/MySQL, JavaScript, CSS, HTML/XHTML in different files and to embed them inside the HTML code with PHP include/require functions or the HTML embed tags for JS/CSS. You can create one file for the top of the page Logo/Navigation, the content, and one more for the bottom of the page for anything else you want to add.http://www.php.nethttp://www.mysql.com
I don't really want to change my whole website. I just want to put some php things onto my html site if that's what you mean.
Link to comment
Share on other sites

Pretty much just saying is if you can, keep the languages separate and get the basics down. Do whatever you want, just trying to make it a little easier for you in editing.
Well firstly, I know nothing about PHP, would I have to change all the HTML to PHP? OR somehow get around this? I have over 80 pages and editing one by one has taken a long time. I was wandering if there is an easier way of adding new products, then having to create a copy of an original product page then changing all the details? How do online stores do it?I would prefer an all PHP site as long as it looks good and is easy to do. I have already spent 2 months making my site takeawaydvds.com using HTML and it has been hard work.Thanks
Link to comment
Share on other sites

I have over 80 pages and editing one by one has taken a long time. I was wandering if there is an easier way of adding new products, then having to create a copy of an original product page then changing all the details? How do online stores do it?
Online stores have one page that displays products. The pages gets sent a product ID, looks up that product in the database, and displays information about the product on the page. That's the easy part. The difficult parts are the backend scripts for adding a new product, deleting a product, or editing an existing product.The first thing you'll need to do is design the database, you need to think about all of the information that you want to save for each product. Obvious things would be the product's title, description, maybe a picture, a price, etc, whatever you want to save. You'll also need a field in the database to hold the product ID, the ID should be an integer that automatically increases, the database can do that. Every time you add a new product it assigns the next ID to that product. Once you design the database to hold the products, then making the page to add a new product is pretty easy, because you just need to put fields on the page to correspond with the database fields. When you hit submit, the page would validate the data (make sure the title isn't blank or the price isn't 0) and add it to the database. The pages for deleting and editing are pretty similar.For the page that displays products, you would send the product ID in the link, like this:show_product.php?id=123The show_product page would get the ID like this:
$id = intval($_GET['id']);

And then you use the ID to look up the product in the database and display all the info wherever it goes on the page.

Link to comment
Share on other sites

Online stores have one page that displays products. The pages gets sent a product ID, looks up that product in the database, and displays information about the product on the page. That's the easy part. The difficult parts are the backend scripts for adding a new product, deleting a product, or editing an existing product.The first thing you'll need to do is design the database, you need to think about all of the information that you want to save for each product. Obvious things would be the product's title, description, maybe a picture, a price, etc, whatever you want to save. You'll also need a field in the database to hold the product ID, the ID should be an integer that automatically increases, the database can do that. Every time you add a new product it assigns the next ID to that product. Once you design the database to hold the products, then making the page to add a new product is pretty easy, because you just need to put fields on the page to correspond with the database fields. When you hit submit, the page would validate the data (make sure the title isn't blank or the price isn't 0) and add it to the database. The pages for deleting and editing are pretty similar.For the page that displays products, you would send the product ID in the link, like this:show_product.php?id=123The show_product page would get the ID like this:
$id = intval($_GET['id']);

And then you use the ID to look up the product in the database and display all the info wherever it goes on the page.

Thanks, is it possible to use an HTML product page and embed the PHP product details?
Link to comment
Share on other sites

You can embed PHP code inside an HTML file, but it will need to be renamed .php.
OK good, I have a database saved online at awardspace phpmyadmin, I have set a number as a primary key. How do I get this data and insert it into my PHP product page? What are the main PHP codes I should know? E.g. to get the specific data from a specific field from the table? And how do I link to that table?
Link to comment
Share on other sites

You should probably read up on how to use MySQL with PHP, it will give you a better understanding of how to use the two together.You use this function to connect:http://www.php.net/manual/en/function.mysql-connect.phpThis sends a SQL query to the database:http://www.php.net/manual/en/function.mysql-query.phpAnd this gets one row from the query result:http://www.php.net/manual/en/function.mysql-fetch-assoc.php

Link to comment
Share on other sites

You should probably read up on how to use MySQL with PHP, it will give you a better understanding of how to use the two together.You use this function to connect:http://www.php.net/manual/en/function.mysql-connect.phpThis sends a SQL query to the database:http://www.php.net/manual/en/function.mysql-query.phpAnd this gets one row from the query result:http://www.php.net/manual/en/function.mysql-fetch-assoc.php
Should the following go in <head> or <body>?
<?php$conn = mysql_connect('localhost', 'mysql_user', 'mysql_password');if (!$conn) {	die('Could not connect: ' . mysql_error());}mysql_select_db('database');$result = mysql_query('select * from table');if (!$result) {	die('Query failed: ' . mysql_error());}/* get column metadata */$i = 0;while ($i < mysql_num_fields($result)) {	echo "Information for column $i:<br />\n";	$meta = mysql_fetch_field($result, $i);	if (!$meta) {		echo "No information available<br />\n";	}	echo "<pre>blob:		 $meta->blobmax_length:   $meta->max_lengthmultiple_key: $meta->multiple_keyname:		 $meta->namenot_null:	 $meta->not_nullnumeric:	  $meta->numericprimary_key:  $meta->primary_keytable:		$meta->tabletype:		 $meta->typedefault:	  $meta->defunique_key:   $meta->unique_keyunsigned:	 $meta->unsignedzerofill:	 $meta->zerofill</pre>";	$i++;}mysql_free_result($result);?>

Link to comment
Share on other sites

PHP can go anywhere. That code just looks like you're trying things out, so you can just put that in its own document, it doesn't need HTML code around it.
Strange, when I save it as .PHP and open it using Mozilla Firefox, it is blank and says "Save file".
Link to comment
Share on other sites

It sounds like the web server needs to be set up to run PHP files. Are you testing this on a server that you setup yourself?
OK never mind about that, I ran it straight from my computer.OK I can now connect to the database but I'm having trouble selecting which row to use and show details of. My code so far is below. I need to change "$result = mysql_query("SELECT * FROM ProductsWHERE Item No.='1'");"to something like get ID that you said but I don't know how to use it.
<?php$con = mysql_connect("pdb1.awardspace.com:3306","tky_products","dragoninn");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("tky_products", $con);$result = mysql_query("SELECT * FROM ProductsWHERE Item No.='1'");while($row = mysql_fetch_array($result))  {  echo $row['Item No.'] . " " . $row['Genre'];  echo "<br />";  }?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...