hi,
i'll supose u have a search form let's call it search.htm in wich u have a
input (type="text" name="keyword") and a submit button.
then u'll have to create a php page (i.e. search.php).
u have to send the value of the text input from the serarch.htm via post or
get to the php page.
now, in the php page, use the value of the input (let's call it $keyword) to
query the database.
mysql_connect("server","login","password") or die ("Please contact website
administrator");
mysql_select_db("stampin");
$keyword=$_post['keyword'];
if trim($keyword)=""{
echo"You don't seem to enter a keyword"
}else{
$sel="select * from quotes where keywords like '%$keyword%'";
$query=mysql_query($sel);
while($row=mysql_fetch_array($query)){
echo "<b>Quote:</b> ".$row["quote"]. "<br>".
"<b>Author:</b> ".$row["author"]."<p>";
}
}
this should work. i did't check the syntax, but i think u got the idea.
if u want to refine your search read about MACH-AGAINST mysql operators.
hth,
toto
----- Original Message -----
From: "Melanie" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, February 23, 2006 4:26 AM
Subject: [php_mysql] Please help with PHP/SQL issue...
>I have a simple table (called 'quotes') in a database (called
> 'stampin'). The table has four fields:
> id (auto-increment and not used in display)
> quote
> author
> keywords
>
>
> What should happen is the user should enter a word in the search box
> and it should check the 'keywords' field in the 'quotes' database.
> When the word from the search matches a keyword, it should display the
> quote ('quote') and then, on the next line, the author ('author').
>
> Right now, it's displaying all the information in the database before
> a search is performed.
>
> Can someone please help fix it and explain what I am doing wrong? My
> code is below (I took the connect info out so I'm not giving out the
> login & password for my database, but the info in it is okay).
>
> Thank you SO much.
>
> <?php
> mysql_connect("server","login","password") or die ("Please contact
> website administrator");
> mysql_select_db("stampin");
> if($HTTP_POST_VARS["keywords"]) {
> $result=mysql_query("SELECT * FROM quotes ".
> "WHERE keywords LIKE \"%".
> addslashes($HTTP_POST_VARS["keywords"])."%\"");
> while($row=mysql_fetch_array($result)) {
>
> echo "<b>Quote:</b> ".$row["quote"]. "<br>".
>
> "<b>Author:</b> ".$row["author"]."<p>";
> }
>
> }
>
> ?>
>
>
>
>
>
>
>
>
>
> The php_mysql group is dedicated to learn more about the PHP/MySQL web
> database possibilities through group learning.
> Yahoo! Groups Links
>
>
>
>
>
>
>
The php_mysql group is dedicated to learn more about the PHP/MySQL web database
possibilities through group learning.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php_mysql/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/