Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Select only first four lines, from Sql text field ?
Old 11-26-2010, 09:16 PM Select only first four lines, from Sql text field ?
Experienced Talker

Posts: 38
Name: EarnGate
Trades: 0
Hello,
We want to Find Related Posts from text field of table
we have posts table contain :
id,title,description,keywords,username,hits[/URL],comments

we want create sql command to get Related posts by keywords
but keywords field type is text " more than 1 keywords "

how we can do that ???


we tried to use this code
PHP Code:
function more_items_keywords($what,$keywords,$html) {
global 
$s,$m;
if (
$html$function_name 'A_parse_part'; else $function_name 'parse_part';
$where get_where_fixed_part('',0,0,$s[cas]);$s[more_items_list]=10;
$table $s[item_types_tables][$what];
$q dq("select * from $table where keywords = '$keywords' order by hits limit 10",1);
while (
$x mysql_fetch_assoc($q)) $items[] = '<a href="'.get_detail_page_url($what,$x[n],$x[rewrite_url],'',5).'">'.$x[title].'</a>';
if (
$items[0])
//$a[items] = implode('<br />',$items);
  //$a[title] = $m['more_'.$what];
  
return implode('<tr><td class="posts" align="right">',$items);
}

it's extract related posts if keywords field have 1 keyword only !!!
so that how we can Select only first four or six lines, from Sql text field ?

can you help
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE

Last edited by earngate; 11-26-2010 at 09:29 PM..
earngate is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-27-2010, 12:17 AM Re: Select only first four lines, from Sql text field ?
Backslider's Avatar
Experienced Talker

Posts: 40
Trades: 0
select * from $table where keywords LIKE '%$keywords%'

You should make that column a FULLTEXT index
Backslider is offline
Reply With Quote
View Public Profile
 
Old 11-27-2010, 09:30 AM Re: Select only first four lines, from Sql text field ?
Experienced Talker

Posts: 38
Name: EarnGate
Trades: 0
we tried
$q = dq("select * from $table where keywords LIKE '%$keywords%' order by rand() limit 3",1);

but its give me same post !!!
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
earngate is offline
Reply With Quote
View Public Profile
 
Old 11-29-2010, 10:51 PM Re: Select only first four lines, from Sql text field ?
Experienced Talker

Posts: 38
Name: EarnGate
Trades: 0
can anyone help ?
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
earngate is offline
Reply With Quote
View Public Profile
 
Old 12-01-2010, 11:13 AM Re: Select only first four lines, from Sql text field ?
Extreme Talker

Posts: 156
Trades: 0
If the related posts are by keywords then you would do something like: select keywords from table where keywords like %THEKEYWORDS% limit 4;
dagaul101 is offline
Reply With Quote
View Public Profile
 
Old 12-02-2010, 07:39 AM Re: Select only first four lines, from Sql text field ?
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
PHP Code:
$kw explode(' '$userKw); $sqlWhere ' WHERE ';
if(
count($kw)==0$sqlWhere =''; else
foreach(
$kw as $w) {
    
$sqlWhere .= 'keywords LIKE "%'.$w.'%" AND'
$sqlWhere substr($sqlWhere0strlen($sqlWhere)-3);
// and use in SELECT ... FROM `table` $sqlWhere 
__________________
you can
Please login or register to view this content. Registration is FREE

Last edited by vectorialpx; 12-02-2010 at 07:41 AM..
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 12-02-2010, 09:46 AM Re: Select only first four lines, from Sql text field ?
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Quote:
Originally Posted by vectorialpx View Post
PHP Code:
$kw explode(' '$userKw); $sqlWhere ' WHERE ';
if(
count($kw)==0$sqlWhere =''; else
foreach(
$kw as $w) {
    
$sqlWhere .= 'keywords LIKE &quot;%'.$w.'%&quot; AND'
$sqlWhere substr($sqlWhere0strlen($sqlWhere)-3);
// and use in SELECT ... FROM `table` $sqlWhere 
Will work if all keywords are matched but not if say, two out of three are.I'm not a MySql expert but I can't think of any way of doing it in one clever/fast query (I'd be delighted to learn if someone finds a way). You could build up a load of boolean clauses based on keyword combinations but I'd do a query for each keyword, storing primary key and hit count in arrays, then do a bit of array matching and shuffling in code to get the desired result.
PaulW is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Select only first four lines, from Sql text field ?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.32182 seconds with 12 queries