/    Sign up×
Community /Pin to ProfileBookmark

Does DB have to be full text for this kind of search query?

hi, im making a search script, the code i’m using is:

[code=php]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<link rel=”stylesheet” type=”text/css” media=”screen” title=”Stylesheet” href=”styles.css”>
</head>

<body>
<!–START OF DIV CODE–>

<div id=”container”>

<div id=”header”>banner</div>

<div id=”menu”><?php include(‘menu.html’); ?></div>

<div id=”content-container”>

<div id=”content”>

<!– ALL CONTENT –>

<?

echo”

<table border=”1″ cellpadding=”0″ cellspacing=”0″ style=”border-collapse: collapse” bordercolor=”#111111″ width=”100%” id=”AutoNumber1″>

<tr>

<td class=”headers” width=”16%” align=”center”>File #</td>

<td class=”headers” width=”16%” align=”center”>Type Of Business</td>

<td class=”headers” width=”17%” align=”center”>Location</td>

<td class=”headers” width=”17%” align=”center”>Gross Revenue</td>

<td class=”headers” width=”17%” align=”center”>Business Price

</font></td>

<td width=”17%” align=”center”>Terms</td>

</tr>”;

//CONNECT TO MYSQL AND DATABASE
$conn=@mysql_connect(“localhost”, “USERNAME”, “PASSWORD”) or die (“Err:Conn”);
mysql_select_db(“majdkgf_capital1”) or die(“Err:Db”);

//CONVERT INFORMATION INTO VARIABLES
$category=$_POST[‘category’];
$keyword=$_POST[‘keyword’];

//FORM THE QUERY
$sql=”select * from businesses_for_sale where ‘$category’ LIKE ‘%$keyword%'”;
$result = mysql_query($sql,$conn);

//TEST IF THERE IS AN ERROR WITH QUERY
if(!$result) die(“query “.$query.” failed with error “.mysql_error());

$number=mysql_num_rows(mysql_query(“$sql”));
echo “Search has returned $number results “;
echo “In the category: $category”;

while ($row = mysql_fetch_array($result))
{
$filenu=$row[‘filenu’];
$Business=$row[‘Business’];
$Location=$row[‘Location’];
$Gross_Sales=$row[‘Gross_Sales’];
$Business_Price=$row[‘Business_Price’];
$Terms=$row[‘Terms’];
echo (”
<tr>
<td class=”result” width=”16%” align=”center”><a href=”http://www.majd-gfx.com/capital-one/show_full_business.php?full_business_file_number=$filenu”>$filenu</a></td>
<td class=”result” width=”16%” align=”center”>$Business</td>
<td class=”result” width=”17%” align=”center”>$Location</td>
<td class=”result” width=”17%” align=”center”>$Gross_Sales</td>
<td class=”result” width=”17%” align=”center”>$Business_Price</td>
<td class=”result” width=”17%” align=”center”>$Terms</td>
</tr>
“);
}

echo”</table> “; ?>

<!– END OF CONTENT –>
</div>
</div>
</div>
<!–END OF DIV CODE–>
</body>
</html>
[/code]

now my question is, on my db, do all the fields have to be full text?

if not, this query is not showing any results even though im searching for exact match…..

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriOct 25.2004 — no they dont have to be full text

change
[code=php]$result = mysql_query($sql,$conn); [/code] to
[code=php]$result = mysql_query($sql);[/code]

and
[code=php]$number=mysql_num_rows(mysql_query("$sql")); [/code] to
[code=php]$number=mysql_num_rows($result); [/code]

and everything should be fine
Copy linkTweet thisAlerts:
@Majd-GFXauthorOct 25.2004 — yeah that returned 0 results again, u can try it by going to www.majd-gfx.com/capital-one/index.php


in case u cared, this is the php code updated

[code=php]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" media="screen" title="Stylesheet" href="styles.css">
</head>

<body>
<!--START OF DIV CODE-->

<div id="container">

<div id="header">banner</div>

<div id="menu"><?php include('menu.html'); ?></div>

<div id="content-container">

<div id="content">

<!-- ALL CONTENT -->

<?

include('config.php');

echo"

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">

<tr>

<td class="headers" width="16%" align="center">File #</td>

<td class="headers" width="16%" align="center">Type Of Business</td>

<td class="headers" width="17%" align="center">Location</td>

<td class="headers" width="17%" align="center">Gross Revenue</td>

<td class="headers" width="17%" align="center">Business Price

</font></td>

<td width="17%" align="center">Terms</td>

</tr>";


//CONNECT TO MYSQL AND DATABASE
$conn=@mysql_connect("$server", "$usermysql", "$passmysql") or die ("Err:Conn");
mysql_select_db("$dbname") or die("Err:Db");

//CONVERT INFORMATION INTO VARIABLES
$category=$_POST['category'];
$keyword=$_POST['keyword'];

//FORM THE QUERY
$sql="select * from businesses_for_sale where '$category' LIKE '%$keyword%'";
$result = mysql_query($sql);

//TEST IF THERE IS AN ERROR WITH QUERY
if(!$result) die("query ".$query." failed with error ".mysql_error());


$number=mysql_num_rows($result);
echo "Search has returned $number results ";
echo "In the category: $category with the keyword: $keyword";

while ($row = mysql_fetch_array($result))
{
$filenu=$row['filenu'];
$Business=$row['Business'];
$Location=$row['Location'];
$Gross_Sales=$row['Gross_Sales'];
$Business_Price=$row['Business_Price'];
$Terms=$row['Terms'];
echo ("
<tr>
<td class="result" width="16%" align="center"><a href="http://www.majd-gfx.com/capital-one/show_full_business.php?full_business_file_number=$filenu">$filenu</a></td>
<td class="result" width="16%" align="center">$Business</td>
<td class="result" width="17%" align="center">$Location</td>
<td class="result" width="17%" align="center">$Gross_Sales</td>
<td class="result" width="17%" align="center">$Business_Price</td>
<td class="result" width="17%" align="center">$Terms</td>
</tr>
");
}

echo"</table> "; ?>

<!-- END OF CONTENT -->
</div>
</div>
</div>
<!--END OF DIV CODE-->
</body>
</html>
[/code]


and in case u'r gonna ask if Auto is in the database heres's a screenshot....

[IMG]http://img.photobucket.com/albums/v417/majd-gfx/db.gif[/IMG]
Copy linkTweet thisAlerts:
@96turnerriOct 25.2004 — hmm i searched cash flow, with 'a' and i get one result, are you sure you are putting in correct data to get results?
Copy linkTweet thisAlerts:
@Majd-GFXauthorOct 25.2004 — im sorry im lost, what do u mean by correct data to search?
Copy linkTweet thisAlerts:
@96turnerriOct 25.2004 — i mean, you have your database that you can look at are you selecting the right category to select results and put in a keyword eg

in businesses_for_sale what do you have under Business if you have say foo, you would select Business and put 'o' in the keyword bit,

thats what i mean by correct data, im sure you are just checking youd be surprised how many later go o damn i was doing this wrong after about 10 posts of my scripts not working, just thought i would rule that out at the start ?
Copy linkTweet thisAlerts:
@Majd-GFXauthorOct 26.2004 — aaaahhhhh im such a newb i don't know what u'r talkin about...can u just tell me how to fix it? lol it's been 3 days and no1's been able to help me...
Copy linkTweet thisAlerts:
@96turnerriOct 26.2004 — ive told you how too fix it and its working, did you search for what i posted one or two posts back, please post some of your database tables rows on here so i can examine that, and tell you what to put when searching to show it works, thanks, Rich
×

Success!

Help @Majd-GFX spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...