homepage Welcome to WebmasterWorld Guest from 54.167.75.155
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Simple database search engine
mikejs




msg:4019567
 12:26 pm on Nov 5, 2009 (gmt 0)

Hi I would like to build a simple full text search database

The database will hold a variety of information on a perticular topic Cars for example I would like to be able to stroe images and text in the database and then have a serch box which will return the results from the database and display them on the page

any suggestions

thanks

M

 

mikejs




msg:4020321
 12:23 pm on Nov 6, 2009 (gmt 0)

Hi ok I have built a simple database with a table

articles id, catagory, title, body, rate

I have built a simple form which I will use to update the database with new articles

I have 3 text boxes catagory, title and body

I would like to validate the form before its submitted to check all the form fields have been compleated

it then posts the data to a simple php form that passes the data to the DB

the form works fine but after submitting the form I get now notice back saying update was ok

if possible on the new article form I would like to be able to display a list of all the articles on the database and then after a new record has been created return the user to the form where the new entry will apear

anyone have any sugestions or links I could use

thanks

M

eelixduppy




msg:4020413
 2:56 pm on Nov 6, 2009 (gmt 0)

[webmasterworld.com...]

There's a thread from our library that will help you get started. Once you get something to start with we can go from there if you need additional help. :)

mikejs




msg:4020511
 5:39 pm on Nov 6, 2009 (gmt 0)

Thanks for the reply I am getting there slowly I have creted a front end and a upload new article page so far so good

I will sort out the main search later its not that dificult just a case of running a full text search accross the tb and then displaying the results :-)

I have created a dynamic list box I would like to use it to run some quiries

<?php
mysql_select_db($database,$connect) or die ("error cannot connect");

$result = mysql_query($database,$connect);

$query="SELECT name,id FROM category";

$result = mysql_query ($query);
echo "<select name=name value=''>Catagory Search</option>";
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[name]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>

say the list box selected is asp.net I want to be able to run a query to display the selected catagory

somthing like select * from . $selected .

how can I add the selected value into the query thanks

M

rocknbil




msg:4020585
 6:46 pm on Nov 6, 2009 (gmt 0)

With the where clause in your select [dev.mysql.com].

Optimizing where clauses [dev.mysql.com] for more info.

JohnCanyon




msg:4020710
 9:31 pm on Nov 6, 2009 (gmt 0)

Something else to consider is the Apache Lucene project. The zend framework offers the ability to easily set up a very powerful text search engine leveraging lucene.

Out of the box you are going to get more mileage from this system than trying to write your own.

Lucene gives you the ability to do more complex searches such as mutli column only searches to:

keyword: "flight:191 destination:new york"

or regular searches..

keyword: "191 new york"

mikejs




msg:4021195
 11:12 am on Nov 8, 2009 (gmt 0)

Thanks for the replies I have put the following together

<?php
if (count($_POST) > 0) {
$search = trim(strtoupper($_POST['searchtxt']));

mysql_select_db ("microsearch")
or die ("Cannot connect to the database");

//run query on database where search value is like table fields
$sql = "SELECT * FROM articles where ( ";
$sql .= " UPPER(title) like '%" . $search . "%' OR ";
$sql .= " UPPER(category) like '%" . $search . "%' OR ";
$sql .= " UPPER(body) like '%" . $search . "%' ";
$sql .= ") order by category";

$q = (mysql_query($sql));
echo $q;
$num_rows = mysql_num_rows($q); ///check no of rows

// while there are rows echo output to produce page of results
if($num_rows>0){
while($d = mysql_fetch_array($q)){
$id = $d['id'];
$title = $d['title'];
$category = $d['category'];
$body = $d['body'];

echo "<div class=\"response\"><p><strong>" . $title . "</strong></p>";
//include("resultsheader.php");
echo $id . ' - ';
echo '<br>';
echo 'Category: ' . $category . '<br>';
echo '<br>';
echo 'Body: ' . $body . '<hr>';
echo "</div>";
}
//end while loop

}else{
echo"<p>Sorry, no search result. Please change keywords and try again.</p>";
}//end if

I need to paginate the results anyone have any sugestions

thanks

M

rocknbil




msg:4021321
 8:13 pm on Nov 8, 2009 (gmt 0)

Sure! paginate PHP site:webmasterworld.com [google.com]

mikejs




msg:4021699
 3:29 pm on Nov 9, 2009 (gmt 0)

Thanks for the reply I think I was looking for a more hands on reply based on my supplied code...

:-) I will continue reading...

rocknbil




msg:4021805
 6:44 pm on Nov 9, 2009 (gmt 0)

Sorry, would have answered more directly but it's a little complex and the approach may vary, as you can see by some of the threads found there.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved