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 03-28-2005, 06:42 PM search engine
Experienced Talker

Posts: 32
Trades: 0
Hi - i have a problem adding a search engine to my php site.

All blankspaces in my database (mySQL driven) have been replaced by   (this is something that cannot be changed) so dan brown appears dan brown.
Therefore when you search for dan brown no results are returned but when you search for dan brown the required results are returned.

Below is the code that i am using on my site:

form code

<td><form action="../search/results.php?name=name">
<br><input name="name" bgcolor="#FFFFFF" class="film_box" size="13" />
&nbsp;

<input name="Submit" type="submit" value="GO"/>
</form>


Results return page code

<?php

$query = "SELECT * FROM IDX Where Name LIKE '%{$_GET['name']}%' "; #19
$result = mysql_query($query)
or die ("Couldn't execute query."); #21

/* Display text before form */
echo "Your search request has returned the following names.\n";

/* Create form containing selection list */
echo "<form action='actor.php' method='get'>\n"; #34
echo "<table>";
$counter=1; #36
while ($row = mysql_fetch_array($result)) #37
{
extract($row); #39
echo "<tr><td valign='top' width='620'>\n";
#42

echo "<b><li><a href='actor.php?actor_id={$row['NameID']}&name={$row['Name']}'>$Name</a></li></b>"; #47
echo "</td>";
#49
echo "</tr>";
$counter++; #51
}
echo "</table>";
echo "
</form>\n";


The above code has been tested and it works - but only when you search for one word!

I am pretty sure that i need to put some code in the results return page that replaces all ' ' with '&nbsp;' - but i would not know where to start! Please iunderstand that i am a relatively novice coder.

Any assistance that you can offer will be greatly appreciate
hershel is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-28-2005, 07:43 PM
aboyd's Avatar
Skilled Talker

Posts: 61
Location: USA
Trades: 0
Quote:
Originally Posted by hershel
Code:
$query = "SELECT * FROM IDX Where Name LIKE '%{$_GET['name']}%'  ";
Change that. It should be like this:

Code:
$clean_name = preg_replace('/\s/', '&nbsp;', trim($_GET['name']));
$query = "SELECT * FROM IDX Where Name LIKE '%$clean_name%'  ";
Note that I haven't tested this code, it's from memory. So if it doesn't work, ask someone here if I left in a typo or syntax error.
__________________

Please login or register to view this content. Registration is FREE
- geek blog & free phpBB mods

Please login or register to view this content. Registration is FREE
- tools & forums for writers

Please login or register to view this content. Registration is FREE
- dating advice for men, from women
aboyd is offline
Reply With Quote
View Public Profile Visit aboyd's homepage!
 
Old 03-28-2005, 09:31 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Trades: 1
That seems a fair answer, but why the:

'%$clean_name%'

Why not:

'$clean_name'

I know it is a tad padantic, but if a coder gets into a habbit like that then that means a lot of characters that are not needed, meaning a slower load with a big project.

Steve.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 03-28-2005, 11:46 PM
aboyd's Avatar
Skilled Talker

Posts: 61
Location: USA
Trades: 0
Gaffer, do you know what the percentage signs do? You can't remove them without removing some of the abilities of his search engine. Leaving them in was deliberate on my part.
__________________

Please login or register to view this content. Registration is FREE
- geek blog & free phpBB mods

Please login or register to view this content. Registration is FREE
- tools & forums for writers

Please login or register to view this content. Registration is FREE
- dating advice for men, from women
aboyd is offline
Reply With Quote
View Public Profile Visit aboyd's homepage!
 
Old 03-29-2005, 03:40 AM
Experienced Talker

Posts: 32
Trades: 0
thanks for your help - the code works but only when i do it like aboyd says - when i took the % signs out the query returned no results.

Thanks a lot once more
hershel is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to search engine
 

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