techiefreak05 Posted August 31, 2006 Share Posted August 31, 2006 you know google does it. but how to do it. when you search .. in your results.. it makes your search terms bold within the results.. how do i do that?oh, heres my search script:[code]<b>Search by Username:</b><form action="" method="post"> <table align="center" border="0" cellspacing="0" cellpadding="3"><tr><td bgcolor="#3399CC"><font color="black">Username:</font></td></tr><tr><td bgcolor="#3399CC"><input type="input" name="query"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="queryBtn" value="-Search-"></td></tr></table></form><br><b>Search by Email:</b><form action="" method="post"> <table align="center" border="0" cellspacing="0" cellpadding="3"><tr><td bgcolor="#3399CC"><font color="black">Email:</font></td></tr><tr><td bgcolor="#3399CC"><input type="input" name="queryEM"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="queryBtnEM" value="-Search-"></td></tr></table></form><b>Search by First Name:</b><form action="" method="post"> <table align="center" border="0" cellspacing="0" cellpadding="3"><tr><td bgcolor="#3399CC"><font color="black">First Name:</font></td></tr><tr><td bgcolor="#3399CC"><input type="input" name="queryFN"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="queryBtnFN" value="-Search-"></td></tr></table></form><br><br><hr><br><b><u><font color=red>Your Results:</font></u></b><br><?$end = round(microtime(true) - $start, 3);echo 'Query completed in <b>' . $end . '</b> seconds';?><center><?phpif($_POST[queryBtn]){$sql = "SELECT * FROM users WHERE username LIKE '%$_POST[query]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "Username: <a href='getInfo.php?user=" .$row[username]. "'>".$row[username]."</a><hr width=50%><br>";}}if($_POST[queryBtnEM]){$sql = "SELECT * FROM users WHERE email LIKE '%$_POST[queryEM]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "Email: " .$row[email]. "<br>";echo "Username: <a href='getInfo.php?user=" .$row[username]. "'>".$row[username]."</a><hr width=50%><br>";}}if($_POST[queryBtnFN]){$sql = "SELECT * FROM users WHERE fname LIKE '%$_POST[queryFN]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "First Name:" .$row[fname]. "<br>";echo "Username: <a href='getInfo.php?user=" .$row[username]. "'>" .$row[username]. "</a><hr width=50%><br>";}}?>[/code] Quote Link to comment Share on other sites More sharing options...
.josh Posted August 31, 2006 Share Posted August 31, 2006 here is an example:[code]<?php$searchword = "the";$searchresult = "the quick brown fox jumps over the fence.";$formattedresult = eregi_replace($searchword, '<b>'.$searchword.'</b>', $searchresult);echo $formattedresult;?>[/code] Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Author Share Posted August 31, 2006 ... thanks .. but idk how to incorporate that into my code.. Quote Link to comment Share on other sites More sharing options...
.josh Posted August 31, 2006 Share Posted August 31, 2006 uh, you would replace $searchword with the word you searched for in your original query, and replace $searchresult with the result you got from the search..? Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Author Share Posted August 31, 2006 thanks, i got it Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Author Share Posted August 31, 2006 well wait! when i search for anything that has a "b" in it.. it shows my <br> tags .. and its not supposed to. Quote Link to comment Share on other sites More sharing options...
joking Posted August 31, 2006 Share Posted August 31, 2006 Here is the updated code:[code]<b>Search by Username:</b><form action="" method="post"> <table align="center" border="0" cellspacing="0" cellpadding="3"><tr><td bgcolor="#3399CC"><font color="black">Username:</font></td></tr><tr><td bgcolor="#3399CC"><input type="input" name="query"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="queryBtn" value="-Search-"></td></tr></table></form><br><b>Search by Email:</b><form action="" method="post"> <table align="center" border="0" cellspacing="0" cellpadding="3"><tr><td bgcolor="#3399CC"><font color="black">Email:</font></td></tr><tr><td bgcolor="#3399CC"><input type="input" name="queryEM"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="queryBtnEM" value="-Search-"></td></tr></table></form><b>Search by First Name:</b><form action="" method="post"> <table align="center" border="0" cellspacing="0" cellpadding="3"><tr><td bgcolor="#3399CC"><font color="black">First Name:</font></td></tr><tr><td bgcolor="#3399CC"><input type="input" name="queryFN"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="queryBtnFN" value="-Search-"></td></tr></table></form><br><br><hr><br><b><u><font color=red>Your Results:</font></u></b><br><?$end = round(microtime(true) - $start, 3);echo 'Query completed in <b>' . $end . '</b> seconds';?><center><?phpif($_POST[queryBtn]){$sql = "SELECT * FROM users WHERE username LIKE '%$_POST[query]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "Username: <a href='getInfo.php?user=" .$row[username]. "'><b>".$row[username]."</b></a><hr width=50%><br>";}}if($_POST[queryBtnEM]){$sql = "SELECT * FROM users WHERE email LIKE '%$_POST[queryEM]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "Email: " .$row[email]. "<br>";echo "Username: <a href='getInfo.php?user=" .$row[username]. "'><b>".$row[username]."</b></a><hr width=50%><br>";}}if($_POST[queryBtnFN]){$sql = "SELECT * FROM users WHERE fname LIKE '%$_POST[queryFN]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "First Name:" .$row[fname]. "<br>";echo "Username: <a href='getInfo.php?user=" .$row[username]. "'><b>" .$row[username]. "</b></a><hr width=50%><br>";}}?>[/code] Quote Link to comment Share on other sites More sharing options...
.josh Posted August 31, 2006 Share Posted August 31, 2006 techiefreak can you repost your modified code? Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Author Share Posted August 31, 2006 yeah, but ididnt post the form.. cuz i didnt change it..[code]<?phpif($_POST[queryBtn]){$sql = "SELECT * FROM users WHERE username LIKE '%$_POST[query]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {$searchword = "$_POST[query]";$searchresult = "Username: <a href='getInfo.php?user=" .$row[username]. "'>".$row[username]."</a><hr width=50%><br>";$formattedresult = eregi_replace($searchword, '<b>'.$searchword.'</b>', $searchresult);echo $formattedresult;}}if($_POST[queryBtnEM]){$sql = "SELECT * FROM users WHERE email LIKE '%$_POST[queryEM]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {$searchword = "$_POST[queryEM]";$searchresult = "Email: " .$row[email]. "<br>Username: <a href='getInfo.php?user=" .$row[username]. "'>".$row[username]."</a><hr width=50%><br>";$formattedresult = eregi_replace($searchword, '<b>'.$searchword.'</b>', $searchresult);echo $formattedresult;}}if($_POST[queryBtnFN]){$sql = "SELECT * FROM users WHERE fname LIKE '%$_POST[queryFN]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "First Name:" .$row[fname]. "<br>";echo "Username: <a href='getInfo.php?user=" .$row[username]. "'>" .$row[username]. "</a><hr width=50%><br>";}}?>[/code]it works yes .. but when i search for "b" .. it shows my <br> tags .. and i know why.. cuz its included in the $searchresult echo .. but idk how to fix it. there is asimple way to fix it.. stop the user from searching for less than 3 charaters.. and im about to try that. Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Author Share Posted August 31, 2006 ...crap.. when i echo the following:[code]Username: <a href='getInfo.php?user=" .$row[username]. "'>".$row[username]."</a>[/code]and the search terms are bolded ..the link is: [code][color=red]getInfo.php?user=<b>searchtermhere</b>[/color][/code][code]and thats a BAD thing! cuz the "<b>" and "</b>" are included in the url[/code] Quote Link to comment Share on other sites More sharing options...
.josh Posted August 31, 2006 Share Posted August 31, 2006 oh i get it. well how about doing for instance:[code]if($_POST[queryBtn]){$sql = "SELECT * FROM users WHERE username LIKE '%$_POST[query]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {$searchword = "$_POST[query]";$searchresult = $row['username'];$formattedresult = eregi_replace($searchword, '<b>'.$searchword.'</b>', $searchresult);echo "Username: <a href='getInfo.php?user=" .$formattedresult. "'>".$formattedresult."</a><hr width=50%><br>";}}[/code] Quote Link to comment Share on other sites More sharing options...
joking Posted August 31, 2006 Share Posted August 31, 2006 Just use the following code[code]<b>Search by Username:</b><form action="" method="post"> <table align="center" border="0" cellspacing="0" cellpadding="3"><tr><td bgcolor="#3399CC"><font color="black">Username:</font></td></tr><tr><td bgcolor="#3399CC"><input type="input" name="query"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="queryBtn" value="-Search-"></td></tr></table></form><br><b>Search by Email:</b><form action="" method="post"> <table align="center" border="0" cellspacing="0" cellpadding="3"><tr><td bgcolor="#3399CC"><font color="black">Email:</font></td></tr><tr><td bgcolor="#3399CC"><input type="input" name="queryEM"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="queryBtnEM" value="-Search-"></td></tr></table></form><b>Search by First Name:</b><form action="" method="post"> <table align="center" border="0" cellspacing="0" cellpadding="3"><tr><td bgcolor="#3399CC"><font color="black">First Name:</font></td></tr><tr><td bgcolor="#3399CC"><input type="input" name="queryFN"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="queryBtnFN" value="-Search-"></td></tr></table></form><br><br><hr><br><b><u><font color=red>Your Results:</font></u></b><br><?$end = round(microtime(true) - $start, 3);echo 'Query completed in <b>' . $end . '</b> seconds';?><center><?phpif($_POST[queryBtn]){$sql = "SELECT * FROM users WHERE username LIKE '%$_POST[query]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "Username: <a href='getInfo.php?user=" .$row[username]. "'><b>".$row[username]."</b></a><hr width=50%><br>";}}if($_POST[queryBtnEM]){$sql = "SELECT * FROM users WHERE email LIKE '%$_POST[queryEM]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "Email: " .$row[email]. "<br>";echo "Username: <a href='getInfo.php?user=" .$row[username]. "'><b>".$row[username]."</b></a><hr width=50%><br>";}}if($_POST[queryBtnFN]){$sql = "SELECT * FROM users WHERE fname LIKE '%$_POST[queryFN]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "First Name:" .$row[fname]. "<br>";echo "Username: <a href='getInfo.php?user=" .$row[username]. "'><b>" .$row[username]. "</b></a><hr width=50%><br>";}}?>[/code] Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Author Share Posted August 31, 2006 CrayonViolet:it 50% works! it doesnt display my br tags.. BUT it still has the b tags in the url .. which brings up a PAGE CANNOT BE DISPLAYED browser error... Quote Link to comment Share on other sites More sharing options...
.josh Posted August 31, 2006 Share Posted August 31, 2006 joking, that code will not work. if you have the string "the quick brown fox" and you searched for "fox" and it returns the string, your code bolds "the quick brown fox" whereas the goal here is to echo the whole string, but have just "fox" bolded. Quote Link to comment Share on other sites More sharing options...
.josh Posted August 31, 2006 Share Posted August 31, 2006 okay repost your code again. i tried the code block i gave you and it seems to work just fine for me... Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Author Share Posted August 31, 2006 haha crayonviolet, i was just gonna say that!! .. so, do you know ho to stop it from putting the b tags in the link.. lets say i searched for "bren".. that would display one result.. as <b>bren</b>den .. ok good, BUT the link will be: [code]getInfo.php?user=<b>bren</b>den[/code] where its supposed to be: [code]getInfo.php?user=brenden[/code] Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Author Share Posted August 31, 2006 i still have the code you posted that DID get rid of showing the br tags in the results.. i hacent chnged anything in the code u gave me. Quote Link to comment Share on other sites More sharing options...
.josh Posted August 31, 2006 Share Posted August 31, 2006 see that's what i don't get. i tried that code on my own server and it seems to work just fine. surely there must be a typo somewheres Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Author Share Posted August 31, 2006 heres the code i have ..[code]<?phpif($_POST[queryBtn]){$sql = "SELECT * FROM users WHERE username LIKE '%$_POST[query]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {$searchword = "$_POST[query]";$searchresult = $row['username'];$formattedresult = eregi_replace($searchword, '<b>'.$searchword.'</b>', $searchresult);echo "Username: <a href='getInfo.php?user=" .$formattedresult. "'>".$formattedresult."</a><hr width=50%><br>";}}if($_POST[queryBtnEM]){$sql = "SELECT * FROM users WHERE email LIKE '%$_POST[queryEM]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "Email: " .$row[email]. "<br>";echo "Username: <a href='getInfo.php?user=" .$row[username]. "'>".$row[username]."</a><hr width=50%><br>";}}if($_POST[queryBtnFN]){$sql = "SELECT * FROM users WHERE fname LIKE '%$_POST[queryFN]%'";$query = mysql_query($sql);while($row = mysql_fetch_array($query)) {echo "First Name:" .$row[fname]. "<br>";echo "Username: <a href='getInfo.php?user=" .$row[username]. "'>" .$row[username]. "</a><hr width=50%><br>";}}?>[/code]or you could click my giant green logo and register(its a whole 5 fields! lol) quick on my site and go to search and search for "bren" or "br" or something in "brenden" Quote Link to comment Share on other sites More sharing options...
.josh Posted August 31, 2006 Share Posted August 31, 2006 replace echo "Username: <a href='getInfo.php?user=" .[b]$formattedresult[/b]. "'>".$formattedresult."</a><hr width=50%><br>";with echo "Username: <a href='getInfo.php?user=" .[b]$searchword[/b]. "'>".$formattedresult."</a><hr width=50%><br>"; Quote Link to comment Share on other sites More sharing options...
.josh Posted August 31, 2006 Share Posted August 31, 2006 or my bad, replace the link's $formattedresult to the $searchresult. [code]echo "Username: <a href='getInfo.php?user=" .$searchresult. "'>".$formattedresult."</a><hr width=50%><br>";[/code] Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Author Share Posted August 31, 2006 yeah, i was gonna say :P lol.. ill try it. so.. what do you think of my site so far? not to get off topic Quote Link to comment Share on other sites More sharing options...
.josh Posted August 31, 2006 Share Posted August 31, 2006 mmm...aah... well green isn't really my color, but that's just me. looks like it's comin' along good so far though..i saw that the links seemed to work, but when i went back and tried again, i got this error:Fatal error: Cannot use [] for reading in /home/www/zycoworld.flamelicker.com/newlayout/search.php on line 57seems you fubared something :) Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted August 31, 2006 Author Share Posted August 31, 2006 haha i know. i put something.. im fixing it now Quote Link to comment Share on other sites More sharing options...
.josh Posted August 31, 2006 Share Posted August 31, 2006 i suggest having the login redirect to the home page instead of dumping you back at the login page. also you should condense your searchboxes into one box with checkboxed options. if you want more advice then i suggest making a new thread in the website critiques forum. Quote Link to comment 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.