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
Old 08-18-2009, 01:51 AM SQL Search
Super Talker

Posts: 102
Trades: 0
I am trying to make search function

to search title name

and the option to search Creation Time, Update Time, Board ID

The structure of the table is

id||board||title||owner||status||priority||views|| createtime||updateuser||updatetime||bumptime||bump s
Aaron™ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-18-2009, 07:11 AM Re: SQL Search
Super Talker

Posts: 102
Trades: 0
I just really need advice on what to use to do this.
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 08-18-2009, 08:19 AM Re: SQL Search
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Code:
select what_you_need
from your_table
where title like '%the_search_term%'
Now, what do you mean by
Quote:
and the option to search Creation Time, Update Time, Board ID
?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-18-2009, 11:02 AM Re: SQL Search
Super Talker

Posts: 102
Trades: 0
WHERE updatetime (is between search time) OR creationtime (is between search time) OR boardid = searchid

but the user will have the OPTION to search them and if one is set search with that, and if 2 then search with 2 of them

and I don't want to have like 5/6 different SQL querys in if statments

Last edited by Aaron™; 08-18-2009 at 11:56 AM..
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 08-18-2009, 07:31 PM Re: SQL Search
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Just create your sql query depending of what the user sends to you...
PHP Code:
$searchTerm==isset($_GET['searchTerm'])?addslashes($_GET['searchTerm']):false;  
$updateTime=isset($_GET['updateTime'])?$_GET['updateTime']:false;  //search in update time ?
$upTimeS=isset($_GET['upTimeS'])?$_GET['upTimeS']:false;  //if yes, from wich time
$upTimeE=isset($_GET['upTimeE'])?$_GET['upTimeE']:false;  //to which time

$creationTime=isset($_GET['creationTime'])?$_GET['creationTime']:false;  //search by creation time
$creaTimeS=isset($_GET['creaTimeS'])?$_GET['creaTimeS']:false;  //if yes, from wich time
$creaTimeE=isset($_GET['creaTimeE'])?$_GET['creaTimeE']:false;  //to which time

$boardId=isset($_GET['boardId'])?$_GET['boardId']:false;  //search by board id ?
$sql=<<<SQL
select what_you_need
from your_table
where title like '%
$searchTerm%'
SQL;
if(
$updateTime!==false){
     
$sql.="or updatetime between '$upTimeS' and '$upTimeE' \n";
}
if(
$creationTime!==false){
     
$sql.="or creationTime between '$creaTimeS' and '$creaTimeE' \n";
}
if(
$boardId!==false){
  
$sql.="or boardid =$boardId";

__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 08-19-2009 at 04:32 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 08-18-2009, 10:18 PM Re: SQL Search
Super Talker

Posts: 102
Trades: 0
Thank you, see I would have never thought to use it like that.
Aaron™ is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to SQL Search
 

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.26833 seconds with 12 queries