Re: Search Database !

From: Date: Sun, 16 Jun 2002 21:33:55 +0000
Subject: Re: Search Database !
Groups: php.general 
Request: Send a blank email to php-general+get-102426@lists.php.net to get a copy of this message
Yea that new one is right. Here's a nice function if you'd like (you'll have to customize to your settings): function search_articles($searchterm, $searchtype) { global $PHP_SELF, $imagesroot; if (!$searchtype || !$searchterm) { echo "You have not entered search details.<br> Please try again."; require("footer.inc.php"); exit; } $searchtype = addslashes($searchtype); $searchterm = addslashes($searchterm); $query = "select * from articles where ".$searchtype." like '%".$searchterm."%'"; $result = mysql_query($query); $num_results = mysql_num_rows($result); if($num_results == "0") { echo "No articles could be found containing <b>$searchterm</b> in the type <b>$searchtype</b>, perhaps you should narrow down your search and try again."; require("footer.inc.php"); exit; } echo "<h3>ModDev.net Article Search</h3>\n"; echo "<p>Number of articles containing <b>$searchterm</b> found: ".$num_results."<p>\n"; for ($i=0; $i <$num_results; $i++) { $row = mysql_fetch_array($result); echo "<table cellpadding=2 cellspacing=0 border=0 width=400>\n"; echo "<tr><td width=12 valign=middle>\n"; echo $i+1; echo ".</td><td>Some result details here</td></tr></table>\n"; } } ----- Original Message ----- From: Dave Barry Sent: Sunday, June 16, 2002 5:22 PM To: php-general@lists.php.net Subject: Re: [PHP] Search Database ! On Sun, Jun 16, 2002 , Septic Flesh <septic_flesh@hotmail.com> wrote: > select * from products where %prod_name% like %ATX% > try select * from products where prod_name like '%ATX%' > > this is wrong . .I try to execute it in the mysql through myphpadmin and I > got error .. > > y ? > > what do I miss ? > > > -- > ~~~~~~~~~~~~~~~~ > > Sapilas@/dev/pinkeye > > ~~~~~~~~~~~~~~~~ > "Chris Shiflett" <shiflett@php.net> wrote in message > news:3D0CF68C.5090603@php.net... > > select * from products where prod_name like '%your_word%' or description > > like '%your_word%'; > > > > Replace "*" with whatever you are searching for *or leave it if you want > > everything), and replace "your_word" with whatever term you are > > searching for. > > > > Chris > > > > Septic Flesh wrote: > > > > >How can I do the following ? > > > > > >I have the following database: > > > > > >Products > > >====== > > >cat_id > > >prod_id > > >prod_name > > >description > > >manu_name > > > > > > > > >The user is going to put a word as input, and I wanna search this word in > > >the database. > > > > > >How do I make this QUERY to search for some letters (the given word) in > the > > >"prod_name" field or in the "description" field ? > > > > > > > > >Thanks in advance ? > > > > > > > > > > > > > > > > > >-- > > >~~~~~~~~~~~~~~~~ > > > > > >Sapilas@/dev/pinkeye > > > > > >~~~~~~~~~~~~~~~~ > > > > > > > > > > > > > > > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Dave Barry - (no, not that one) Don't believe in the system. dave@mikamyla.com --Michael Franti -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpGet more from the Web. FREE MSN Explorer download : http://explorer.msn.com

« previous php.general (#102426) next »