...

View Full Version : php search box form...



mia_tech
08-05-2008, 12:48 AM
I decided to do a search box following this php script http://php.about.com/od/phpwithmysql/ss/php_search_3.htm which seems very simple, in my case I'm not using the options form only a simple search box, and the visitors will be searching for articles, but how should I go about input the article info on the table; I created a table called articles, with columns "name", "date", "description", "url"... my doubt is with the description column, should I enter the whole article in there, the first lines or a descriptive content about that specific article, it seemed to me that entering the whole content would take sometime, although there are tools to do bulk insert into mysql....I want that when users search they get back the title of the article with at least the first 2 or 3 lines, the date, and the url... yes, yes I know this can be done with google

any help appreciated

www.pctechtips.org

masterofollies
08-05-2008, 03:27 AM
I would hardcode the entire article in your script, it'd be too much on the database to pull out a whole page of text out.

mia_tech
08-05-2008, 04:56 AM
I'm just trying to get an idea how this is done..... how could I hard code the articles in the script... hint :0)


thanks

www.pctechtips.org

mia_tech
08-06-2008, 09:04 AM
I came up with my own search script the one found on the link above didn't quite worked for me, but still have a problem... and is that no matter what I search for I'm getting the whole content of the table back and the problem is on the sql string which I'm using
SELECT * FROM articles and I realize that I should be using some sort of condition on my sql statement to match the user search, but I can put it into php terms if someone could give a hand....here the php code

<?php
//open connection
$conn = mysql_connect("localhost", "root", "password") or die(mysql_error());
//select database
mysql_select_db("test", $conn);
//the sql statement
$sql = "SELECT * FROM articles";
//execute the statement
$data = mysql_query($sql, $conn) or die(mysql_error());
while ($result = mysql_fetch_array($data)) {
//giving names to the fields
$title = $result['title'];
$date = $result['date'];
$info = $result['info'];
$url = $result['url'];
//put the results on the screen
echo "<b>$title</b>";
echo " ";
echo "<b>$date</b><br>";
echo "$info<br>";
echo "$url<br>";
}
?>


and here is the search form

<h2>Search</h2>
<form name="search" method="post" action="search1.php">
Seach for: <input type="text" name="find" />
<input type="submit" name="search" value="Search" />
</form>

thanks

www.pctechtips.org



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum