Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

PHP/MySQL Search SQL

Explorer ,
Mar 13, 2007 Mar 13, 2007

Copy link to clipboard

Copied

I am trying to build a search page on my site. I am wanting it to search by "name". I have it wokring is someone types in the whole name exactly.


mysql_select_db($database_siteText, $siteText);
$query_Recordset1 = sprintf("SELECT * FROM reviews WHERE review_name = %s", GetSQLValueString($colname_Recordset1, "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $siteText) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

When I click test in DW and it give me the box to type in, if I put the whole name it works fine. However I would like it find part of the name too. Is there a wildcard I should use.

Ex. Complete name in database "John Doe"

If I type exactly that it works fine but I would like it where a user can just type "john" and get a list of ever name that includes john.

Thanks
TOPICS
Server side applications

Views

446
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007

Copy link to clipboard

Copied

On Wed, 14 Mar 2007 05:54:19 +0000 (UTC), "newhorizonhosting.com"
<charles@dieselinteractive.com> wrote:

> If I type exactly that it works fine but I would like it where a user can just
>type "john" and get a list of ever name that includes john.

You'll need to use a SQL query like this:

SELECT * FROM reviews WHERE review_name LIKE "%$searchterm%"

If you use "%$searchterm%" it looks for your search term with anything
at either end, or you can just use a single % in which case it looks
for anything either before or after your search word (delending where
you put the %).
--
Steve Fleischer
steve at flyingtigerwebdesign dot com
Hong Kong

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 14, 2007 Mar 14, 2007

Copy link to clipboard

Copied

Below is the code I made in dreamweaver. Where/how should I modify it to ad the %.

I want them at the front and back of the search term.

$colname_Recordset1 = "-1";
if (isset($_GET['searchterm'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['searchterm'] : addslashes($_GET['searchterm']);
}
mysql_select_db($database_siteText, $siteText);
$query_Recordset1 = sprintf("SELECT * FROM reviews WHERE review_name LIKE %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $siteText) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied

newhorizonhosting.com wrote:
> Below is the code I made in dreamweaver. Where/how should I modify it to ad the
> %.
>
> I want them at the front and back of the search term.

Steve is right in saying that % is the SQL wildcard, but you don't need
to add it directly into the code.

In the Recordset dialog box, set Filter to review_name, the drop-down
menu alongside to "contains", and the other two drop-downs to URL
parameter and searchterm. Dreamweaver then creates the correct code for you.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied


David -

I am not really understanging what you are saying.

If you look at my search page below and try searching for "chipotle" it works find as long as you use the who word. But if tyou search for "chipotl" it does not return any results.

http://dfwfoodguide.com/search.php

An I can see from this example that it works if I add the wildcard myself in the url

http://dfwfoodguide.com/search_results.php?searchterm=chipotl%
http://dfwfoodguide.com/search_results.php?searchterm=%hipotl%

So I gues my questions is what do I need to do, to get the wild card add to my string

Thanks
C

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied

I think I understand. I dod not see that because was not in the simple dialog box. I now see it.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied

LATEST
newhorizonhosting.com wrote:
> I think I understand. I dod not see that because was not in the simple dialog box. I now see it.

You can also do it in the Advanced dialog box by setting variables, but
for a single table and the simple query you're doing, the Simple dialog
box is easier to use.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines