/    Sign up×
Community /Pin to ProfileBookmark

Seacrch text using php

Hai friends

I have got the contents from database But i need to search the content if any worsd available in the contents

For example when I get the pargraph from the table then i find “Style” this word is avaliable in the paragraph .

How can i find the text in the paragraph?

Thanks
Prabu

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@pcthugNov 25.2006 — There are much more advanced techniques (Fulltext, RLIKE, Multiple terms split upon Whitespace, etc.), but the following should fulfill your requirements (provided totally untested):
[code=php]
$table = 'the_table'; // table you'd like to search
$columns = array('paragraph', 'title'); // columns you'd like to search

$terms = 'Style'; // replace this with your search term(s)

$order = 'title'; // (optional) would you like your result order by a column
$clause = 'ASC'; // (optional) if order is set, would you like results returned in ascending (ASC) or descending (DESC) order
$start = 10; // (optional) how many rows would you like ignore before
$limit = 20; // (optional) how many results would you like to be returned

simpleDbSearch($table, $columns, $terms, $order, $clause, $start, $limit));

/*
bool simpleDbSearch ( string table, array columns, string terms [, string order [, string clause [, int start [, int limit ]]]] )

*/
function simpleDbSearch($table, $columns, $terms, $order = NULL, $clause = NULL, $start = 0, $limit = 0)
{
$sql = "SELECT * FROM $table WHERE ";

if(!is_array($columns))
return trigger_error('columns argument must be an array', E_USER_WARNING);

foreach($columns as $value)
$sql .= "$value LIKE '%$terms%' ";

if(!is_null($order))
$sql .= "ORDER BY $order ";

if(!is_null($order))
{
$sql = strtoupper($str);
if($sql != 'ASC')
$sql .= 'DESC ';
else
$sql .= 'ASC ';
}

if($start < $limit && $start >= 0)
$sql .= "LIMIT $start, $limit";

$result = @mysql_query($sql);

if(!$result) // bad query
return false;

if(mysql_num_rows($result) < 1) // no results
return false;

while($results = mysql_fetch_assoc())
{
echo OUTPUT<<<
// your output template here (results stored in the $results associative-array)
OUTPUT;
}

return true;
}
[/code]
×

Success!

Help @vssp 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,
)...