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 04-26-2005, 12:18 AM Search
simjay's Avatar
Experienced Talker

Posts: 31
Location: UK
Trades: 0
Hello I have been trying to get a search feature to my site:

Search.php

PHP Code:
<form name="form" action="searching.php" method="get">
  <
input type="text" name="q" />
  <
input type="submit" name="Submit" value="Search" />
</
form
Searching.php
PHP Code:
<?php

  $var 
= @$_GET['q'] ;
  
$trimmed trim($var); 
    
        
$sql "SELECT * FROM adddb where nameof = '$trimmed' order by nameof";
            
$result mysql_query($sql$conn) or die(mysql_error());
                while (
$newArray mysql_fetch_array($result)) {
                     
                    
$id $newArray['id'];
                    
$nameof $newArray['nameof'];
                    
$why $newArray['why'];                    
                    
$link "view.php?id";                    
    
            echo 
"$nameof<br>$why";
        }        
?>

At the moment it only returns exact search words, i have tried % but not working, can any one help?
__________________

Please login or register to view this content. Registration is FREE
- Hosting From £9.99PY 500MB Space - 10GB Bandwidth - Domains From £8.00PY
simjay is offline
Reply With Quote
View Public Profile Visit simjay's homepage!
 
 
Register now for full access!
Old 04-26-2005, 02:25 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
where nameof  LIKE '%$trimmed%'
Changes in red
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-26-2005, 08:24 AM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
That should probably have some explanation with it chrishirst.

The LIKE will tell mySQL to look through which ever fields you have asked the query to look through for any word contained in the quotes following the LIKE statement.

You'll also notice that chrishirst has put % operators at the beginning and end of the keyword, these are mySQLs wild cards, that means that (say the key word is "bob") then the query can find anything within the data such as bob, bobby, billybob, etc. That's because the wildcards are at either end, so as you can imagine if it was simply 'bob%' it would find bob, bobby but not billybob. You don't HAVE to use the wildcard, only if you want a more open, result yielding search.

Also, i'd advise that you check out the mySQL Manual on what it has to say about the LIKE statement. I would give you a link, but the mySQL manual is so bloody rubbish I can't actually find reference to it...
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to 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.50337 seconds with 12 queries