OLM3CA Posted September 19, 2006 Share Posted September 19, 2006 I want to search a word more than one column in table but result doesnt change while I add the other columns.Is there something wrong with the usage of the below code ?[code]<?php $query="SELECT * FROM link WHERE words LIKE '%".$sword."%' OR url LIKE '%".$sword."%' AND status ='1' LIMIT $from, $max_results";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21331-searching-more-than-1-column/ Share on other sites More sharing options...
Barand Posted September 20, 2006 Share Posted September 20, 2006 When mixing OR and AND use (..) to specify the logicIs it[code]$query="SELECT * FROM link WHERE (words LIKE '%".$sword."%') OR ((url LIKE '%".$sword."%') AND (status ='1')) LIMIT $from, $max_results"; [/code]or is it[code] $query="SELECT * FROM link WHERE ((words LIKE '%".$sword."%') OR (url LIKE '%".$sword."%')) AND (status ='1') LIMIT $from, $max_results"; [/code] Quote Link to comment https://forums.phpfreaks.com/topic/21331-searching-more-than-1-column/#findComment-94995 Share on other sites More sharing options...
OLM3CA Posted September 20, 2006 Author Share Posted September 20, 2006 Thank you I have done that query but I got error,Something wrong with the query but what ?[code] Warning: mysql_result(): supplied argument is not a valid MySQL result resource in ... [/code][code]<?php // This query works fine I think. $query="SELECT * FROM links WHERE ((keywords LIKE '%".$sword."%') OR (url LIKE '%".$sword."%') OR (aciklama LIKE '%".$sword."%') OR (baslik LIKE '%".$sword."%')) AND (status ='1') LIMIT $from, $max_results"; $result=mysql_query($query); // The problem is in this query I guess $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM links WHERE ((keywords LIKE '%".$sword."%') OR (url LIKE '%".$sword."%') OR (aciklama LIKE '%".$sword."%') OR (baslik LIKE '%".$sword."%')) AND (status ='1')"),0); ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21331-searching-more-than-1-column/#findComment-95718 Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 When using mysql_result(), don't use inline code, assign the result to a variable first...change this:[code=php:0]$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM links WHERE ((keywords LIKE '%".$sword."%')OR (url LIKE '%".$sword."%') OR (aciklama LIKE '%".$sword."%') OR (baslik LIKE '%".$sword."%')) AND (status ='1')"),0);[/code]to this:[code=php:0]$totalsql = "SELECT COUNT(*) as Num FROM links WHERE ((keywords LIKE '%".$sword."%') OR (url LIKE '%".$sword."%')OR (aciklama LIKE '%".$sword."%') OR (baslik LIKE '%".$sword."%')) AND (status ='1')";$sqlresult = mysql_query($totalsql);$total_results = mysql_result($sqlresult, 0);[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21331-searching-more-than-1-column/#findComment-95730 Share on other sites More sharing options...
OLM3CA Posted September 20, 2006 Author Share Posted September 20, 2006 Thank you for your reply but the same problem still continious... Quote Link to comment https://forums.phpfreaks.com/topic/21331-searching-more-than-1-column/#findComment-95741 Share on other sites More sharing options...
Barand Posted September 20, 2006 Share Posted September 20, 2006 Try to find out why query gives error (I agree Huggie, don't use mysql_query inline).Try[code]<?php$result = mysql_query("SELECT COUNT(*) as Num FROM links WHERE ((keywords LIKE '%".$sword."%') OR (url LIKE '%".$sword."%') OR (aciklama LIKE '%".$sword."%') OR (baslik LIKE '%".$sword."%')) AND (status ='1')") or die (mysql_error());$total_results = mysql_result($result, 0); ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21331-searching-more-than-1-column/#findComment-95745 Share on other sites More sharing options...
OLM3CA Posted September 21, 2006 Author Share Posted September 21, 2006 Thank you very much I am so ashamed that I have done a vaiable name mistake I am sorry thank you for your help but I have learned not to use mysql_result in line code thank you. Quote Link to comment https://forums.phpfreaks.com/topic/21331-searching-more-than-1-column/#findComment-95751 Share on other sites More sharing options...
Barand Posted September 21, 2006 Share Posted September 21, 2006 [quote]Thank you very much I am so ashamed that I have done a vaiable name mistake [/quote]Haven't we all.Get into the habit of using ... or die(mysql_error()), or better still, something like this, so you can also print the query giving the problem[code]$sql = "SELECT bla etc"$result = mysql_query ($sql) or die (mysql_error() . " in <p>$sql</p>");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21331-searching-more-than-1-column/#findComment-95760 Share on other sites More sharing options...
OLM3CA Posted September 21, 2006 Author Share Posted September 21, 2006 ok I take your advises and will apply them.thanks Quote Link to comment https://forums.phpfreaks.com/topic/21331-searching-more-than-1-column/#findComment-95764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.