iyeru42 Posted March 18, 2007 Share Posted March 18, 2007 Hey W3C, I recently put some DB Tables of mine (They're MySQL) and I was wondering how I would get my PHP Scripts to do fulltext searching (or any fulltext option really.) Because it's a pain to have a boat load of queries when there isn't a need to have them. Link to comment Share on other sites More sharing options...
Anders Moen Posted March 18, 2007 Share Posted March 18, 2007 Hello.For the first, this is not W3C. This is W3S. W3C is here I think.What you mean is that you want to make a search engine so you can search through a table in your database? I made a search engine not too long ago that works just fine. I'll post the code here. <form action="" method="get"><input type="text" name="check" value="<?php echo "" . $_GET['check'] . ""; ?>" size="20" /><input type="submit" name="submit" value=" Search " /></form><?php$con = mysql_connect("localhost", "username", "password");if (!$con) {die('Could not connect ' . mysql_error());}mysql_select_db("db_name", $con);if (isset($_GET[submit])) {$check = mysql_real_escape_string($_GET['check']); // You might not need the mysql_real_escape_string here, but I just put it on;)if (empty($check)) {die('You need to fill in at least one letter!');}echo "You searched for: {$check} <br />";echo "<br />";echo "<br />";echo "<b>You got";$result = mysql_query("SELECT * FROM table_name WHERE title LIKE '%$check%'");echo " " . mysql_num_rows($result) . " result(s).</b>";echo "<br /><br />";while ($row = mysql_fetch_array($result)) {echo "<a href=\"news.php?id=" . $row['id'] . "\">";echo stripslashes($row['title']);echo "</a>";echo "<br />";}}?> This is taken directly from the site where I have the search engine. So just change what you need to change Link to comment Share on other sites More sharing options...
iyeru42 Posted March 18, 2007 Author Share Posted March 18, 2007 No, it's not that. I want to implement fulltext to a script that I use. What you did there wasn't fulltext enabled, correct? If it is, show me where. Link to comment Share on other sites More sharing options...
Anders Moen Posted March 18, 2007 Share Posted March 18, 2007 Hm, okay...I'm not sure what you mean then. Could you explain better please? Hehe Link to comment Share on other sites More sharing options...
iyeru42 Posted March 18, 2007 Author Share Posted March 18, 2007 Well, as I said... without fulltext functions for a script, such as a message board, editing a post with about 200 words would cause 20~40 queries to be used. However, with PHP implemented with fulltext (Like IPB, phpBB and SMF do) the queries would go down to a constant number. Link to comment Share on other sites More sharing options...
boen_robot Posted March 18, 2007 Share Posted March 18, 2007 Well, that is why database tables can have multiple columns and each column can have different information. Among the datatypes you can use for each column there is "text" which allows for unlimited text (such as a whole post) to be entered in it.So, when you need the text for a certain post, you'll query the text field with the targeted post ID, or post associated with a certain topic ID. For example, this forum has topics table with each topic having it's name and ID. There is another post table with each post ID associated with a certain topic ID. When you enter showtopic=####, the PHP gets all posts associated with that topic ID as well as the topic title. I mean it doesn't searches for the text itself, but for the ID associated with it. Link to comment Share on other sites More sharing options...
iyeru42 Posted March 18, 2007 Author Share Posted March 18, 2007 The table is already in multiple columns and fields. Link to comment Share on other sites More sharing options...
boen_robot Posted March 18, 2007 Share Posted March 18, 2007 The table is already in multiple columns and fields.OK, so... your point? Any sample table(s) and desired result(s). Link to comment Share on other sites More sharing options...
iyeru42 Posted March 19, 2007 Author Share Posted March 19, 2007 Technically, the desired results are read by my message board (OvBB) and are selected as from the below table. But since OvBB doesn't use fulltext when getting posts via SQL in PHP (Even if the SQL fields are in fulltext) the queries go from 40~150+.Sorry if the image stretches the page, but unfortunately my ISP (Merr.com) said Imageshack.us was having difficulties. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2007 Share Posted March 19, 2007 Fulltext searching in MySQL is essentially just using the LIKE clause in a query, it doesn't need support from PHP or really have anything to do with PHP. You do need a fulltext index on the table to be searched though. Check this for some examples and discussion:http://www.google.com/search?client=opera&...-8&oe=utf-8 Link to comment Share on other sites More sharing options...
iyeru42 Posted March 19, 2007 Author Share Posted March 19, 2007 Thanks, that helps. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now