Jump to content


Photo

how to BOLD search terms in results??


  • Please log in to reply
24 replies to this topic

#1 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 08:40 AM

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:
<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>
<?php
if($_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>";
}
}
?>

Link shortener with advanced, detailed statistics:

http://tyny.us/

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 31 August 2006 - 08:53 AM

here is an example:

<?php
$searchword = "the";
$searchresult = "the quick brown fox jumps over the fence.";

$formattedresult = eregi_replace($searchword, '<b>'.$searchword.'</b>', $searchresult);
echo $formattedresult;
?>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 08:56 AM

... thanks .. but idk how to incorporate that into my code..
Link shortener with advanced, detailed statistics:

http://tyny.us/

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 31 August 2006 - 08:59 AM

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..?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 09:08 AM

thanks, i got it
Link shortener with advanced, detailed statistics:

http://tyny.us/

#6 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 09:10 AM

well wait! when i search for anything that has a "b" in it.. it shows my <br> tags .. and its not supposed to.
Link shortener with advanced, detailed statistics:

http://tyny.us/

#7 joking

joking
  • Members
  • PipPip
  • Member
  • 29 posts
  • LocationLebanon

Posted 31 August 2006 - 09:11 AM

Here is the updated 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>
<?php
if($_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>";
}
}
?>

Just JoKinG

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 31 August 2006 - 09:14 AM

techiefreak can you repost your modified code?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#9 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 09:17 AM

yeah, but ididnt post the form.. cuz i didnt change it..

<?php
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 = "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>";
}
}
?>

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.
Link shortener with advanced, detailed statistics:

http://tyny.us/

#10 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 09:20 AM

...crap.. when i echo the following:

Username: <a href='getInfo.php?user=" .$row[username]. "'>".$row[username]."</a>
and the search terms are bolded ..

the link is:
[color=red]getInfo.php?user=<b>searchtermhere</b>[/color]
and thats a BAD thing! cuz the "<b>" and "</b>" are included in the url

Link shortener with advanced, detailed statistics:

http://tyny.us/

#11 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 31 August 2006 - 09:22 AM

oh i get it. well how about doing  for instance:

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>";

}
}

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#12 joking

joking
  • Members
  • PipPip
  • Member
  • 29 posts
  • LocationLebanon

Posted 31 August 2006 - 09:25 AM

Just use the following 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>
<?php
if($_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>";
}
}
?>

Just JoKinG

#13 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 09:29 AM

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...
Link shortener with advanced, detailed statistics:

http://tyny.us/

#14 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 31 August 2006 - 09:31 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#15 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 31 August 2006 - 09:33 AM

okay repost your code again. i tried the code block i gave you and it seems to work just fine for me...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#16 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 09:35 AM

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:
getInfo.php?user=<b>bren</b>den
where its supposed to be:
getInfo.php?user=brenden

Link shortener with advanced, detailed statistics:

http://tyny.us/

#17 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 09:37 AM

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.
Link shortener with advanced, detailed statistics:

http://tyny.us/

#18 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 31 August 2006 - 09:38 AM

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
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#19 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 31 August 2006 - 09:40 AM

heres the code i have ..
<?php
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>";

}
}

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>";
}
}
?>

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"
Link shortener with advanced, detailed statistics:

http://tyny.us/

#20 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 31 August 2006 - 09:52 AM


replace

echo "Username: <a href='getInfo.php?user=" .$formattedresult. "'>".$formattedresult."</a><hr width=50%><br>";

with

echo "Username: <a href='getInfo.php?user=" .$searchword. "'>".$formattedresult."</a><hr width=50%><br>";

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users