Page 1 of 1
HOW TO ... search engine
Posted: Sat Aug 22, 2009 12:37 pm
by scaleautostyle
hi everybody. i'm a newby in php. i have some basic , VERY basic skill in php. building the database was a lot more easier....
i want to built a search engine for my website but i have some problem.
i search all around the net and found some ready to go search engine. but they are not like what i want. in fact it's nothing like what i want to do. so i decide i will built it from scratch.
BUT maybe someone here is able to help me. on these.
you can found at this url what i want to do.. it's built in html but gave a good idea of the final product.
http://scale24-25.com/wheelDB-site.php
i know how to make a connection to a database. so i don't put any info about my database in this page. but i put the table name refer to.
in fact i want to know how make my dropdown to search in my table the field = of what i want. + how to setup the GO button.
i know it's a lot in one post but it's the only way i found to ask it.
thank's in advance for you help
sebastien
Re: HOW TO ... search engine
Posted: Sat Aug 22, 2009 1:30 pm
by jackpf
Well...any basic database search will include a SELECT query, probably using LIKE (or MATCH AGAINST for fulltext searches) clauses.
I suggest you look up a mysql tutorial. Tizag.com is normally good for beginners.
Re: HOW TO ... search engine
Posted: Sat Aug 22, 2009 6:32 pm
by scaleautostyle
jackpf wrote:Well...any basic database search will include a SELECT query, probably using LIKE (or MATCH AGAINST for fulltext searches) clauses.
I suggest you look up a mysql tutorial. Tizag.com is normally good for beginners.
thank you very much for this site.. i just pass over the mysql, php tutorial and they are nicely done. i found mostly all of what i learn a couple time ago but better explain.
the question is and it was not answer in all the TUTO in this site...
when i made a SELECT * FROM a table and return me duplicate name. how can void this to get only one time each name. i see using SELECT DISTINCT but hwat is the right syntax in php for my query.
thank's in advance
sebastien
Re: HOW TO ... search engine
Posted: Sat Aug 22, 2009 7:19 pm
by jackpf
You got it, DISTINCT is what you need. You need to place DISTINCT before the colmn you wish distinct from in the select clause.
Like so:
[sql]SELECT DISTINCT fieldname FROM TABLE;[/sql]
damn, I don't have backticks on my iPod... But you get the idea

Re: HOW TO ... search engine
Posted: Sat Aug 22, 2009 8:16 pm
by scaleautostyle
jackpf wrote:You got it, DISTINCT is what you need. You need to place DISTINCT before the colmn you wish distinct from in the select clause.
Like so:
[sql]SELECT DISTINCT fieldname FROM TABLE;[/sql]
damn, I don't have backticks on my iPod... But you get the idea

thank's i was doing that in my local server and it doesn't work but i try it on my host server and.... wow it's work there

anyway thank's for the hint it's confirm what i tought.
you can check what is look like at this point.. ( i know the styling is not good.. i will made a CSS for that. )
http://scale24-25.com/wheelDB-site.php
now 2 more thing to do:
first the keyword... i try to figure a logical way it will search but unfortunotly nothing founds. also what will be the rigth way to syntax the query.
and the last one... but it will be the hardest one i think... the submit button... how do you configure that.
thank's in advance
sebastien
Re: HOW TO ... search engine
Posted: Sat Aug 22, 2009 8:41 pm
by scaleautostyle
this is the code i use for the dropdown.
Code: Select all
<?php
$sql = mysql_query("SELECT DISTINCT genric_diam FROM wheels_tires ");
$options = '';
echo '<select genric_diam="genric_diam"><option>select diameter of the wheel</option>';
while($row = mysql_fetch_array($sql)) {
$thing = $row['genric_diam'];
echo '<option>'.$thing.'</option>';
}
echo '</select>';
?>
is it right?? based on what i want to do i think it is but if you have a beeter way to do let me know
thank's
sebastien
Re: HOW TO ... search engine
Posted: Sun Aug 23, 2009 4:54 am
by jackpf
Yeah, that seems fine.
Basically, you can select relevant rows from the database like this:
Code: Select all
$search = mysql_real_escape_string($_POST['search']);
$sql = mysql_query("SELECT * FROM `yourtable` WHERE `the_field` LIKE '%$search%';");
I'm not sure what you mean by "configure the submit button"...
Re: HOW TO ... search engine
Posted: Sun Aug 23, 2009 7:37 am
by scaleautostyle
jackpf wrote:
I'm not sure what you mean by "configure the submit button"...
i mean.. when you select one or more field from the dropdown OR you enter a keyword you have to click on the submit button to get the resul of your search.
what kid of code i have to put under this button to do this. OR do you have a place that i can find the answer. i look at the site you gave me but find nothing.
thank's in adance
sebastien
PS:
Code: Select all
$search = mysql_real_escape_string($_POST['search']);
$sql = mysql_query("SELECT * FROM `yourtable` WHERE `the_field` LIKE '%$search%';");
is it for the keyword filed search??
Re: HOW TO ... search engine
Posted: Sun Aug 23, 2009 7:57 am
by jackpf
HTML forms
And yeah, that's for the keyword. You'd have to change it a bit to accept the select boxes and so on...but that's the base of the query.
Re: HOW TO ... search engine
Posted: Sun Aug 23, 2009 10:29 am
by scaleautostyle
thank's for the link but it what i already done for my text box. see below the code i use
Code: Select all
<div align="center">Keywords
<input type="text" name="keyword" id="keyword" /
</div>
i try to figure out where to include the code you gave me but

i think i'm a bit to tired i don't figur it.
can you gave me an other hint... ( not doing it for me... i have to do it... it's the only way to learn and understand what we are doing but just an other hint.. i think it will be good.. ( i hope )
thank's
sebastien
Re: HOW TO ... search engine
Posted: Sun Aug 23, 2009 10:43 am
by jackpf
Well, you have a <form> element.
Within the <form> element, you can have <select>, text <input> elements....etc. Checkboxes..buttons...and so on.
To submit the form, you have a submit element: <input type="submit">, which submits the form.
They're the basics anyway...
I suggest you run through the examples on w3schools.com.
Re: HOW TO ... search engine
Posted: Sun Aug 23, 2009 12:54 pm
by scaleautostyle
super now i know how it's work for a form to return the info put in the from text field. but i try to find how i can do this simple task... choos the 1/24 from my scale drop down + choose fujimi in my manufaturer dropdown and then click on submit and get the result FROM the database of all 1/24 fujimi i have by reteiving this info
scale, manufacturer_name and kit_number value.
is it possible to do that with this kind of page i have here
Code: Select all
http://scale24-25.com/wheelDB-site.php
thank's
sebastien
PS: if yes what kind of syntax it will get. i thnk i have to use a loop but not sure.
Re: HOW TO ... search engine
Posted: Sun Aug 23, 2009 3:39 pm
by jackpf
Yeah, it's possible.
Tbh, I think you need to go and find a good mysql tutorial, sit down for a couple of hours and read it.
It'll explain stuff like what you're trying to achieve in greater detail than I do.
I'm sure at the end of it you'll be able to do this easily.
All the best,
Jack.