hi.
i'm trying to bold the search criteria i enter into a form. here's the code i have below:
HTML FORM
<form action=search.php method=GET>
Search For:
<p>
<input type=text name=s1 size=35 maxlength=100> in table
<select name="table">
<option></option>
<option name="uwnorman" value="uwnorman" selected>Index</option>
<option name="emergency" value="emergency" >Emergency Numbers and Hotlines</option>
<option name="churhces" value="churhces">Churches</option>
<option name="support" value="support">Support Groups</option>
<option name="clubs" value="clubx">Clubs, Civic, & Social Groups</option>
<option name="city" value="city">City Government</option>
<option name="county" value="county">Cleveland County Government</option>
<option name="state" value="state">Oklahoma State Government</option>
<option name="federal" value="federal">US Federal Government</option>
</select>
<p>
<input type=submit value=Search name=search> <input type=reset value=Clear name=clear>
</form>
SEARCH.PHP
$query = "SELECT * FROM $table where organization LIKE '%$s1%' ";
echo "$query";
echo "<br>";
echo "$s1";
echo "<br>";
echo eregi_replace("($s1)", "<b>\\1</b>", $s1);
echo "<br>";
echo "<h1>Search Results</h1>\n";
// Start a table, with column headers
echo "\n<table>\n<tr>\n" .
"\n\t<th>First Name</th>" .
"\n\t<th>Last Name</th>" .
"\n</tr>";
// Until there are no rows in the result set,
// fetch a row into the $row array and ...
while ($row = @ mysql_fetch_row($result))
{
// ... start a TABLE row ...
echo "\n<tr>";
// ... and print out each of the attributes
// in that row as a separate TD (Table Data).
foreach($row as $data){
eregi_replace("($s1)", "<b>\\1</b>", $s1);
echo "\n\t<td> $data </td>";
}
// Finish the row
echo "\n</tr>";
}
// Then, finish the table
echo "\n</table>\n";
echo "<br><br><br>";
$criteria = "php";
$str = "PHP is great. Isn't php great? I like Php.";
echo eregi_replace("($criteria)", "<b>\\1</b>", $str);
echo "<br>";
The bottom and top eregi_replace functions work correctly and bold the search criteria but I want the criteria to be bolded in the table (foreach ($row as $data) etc.) where it will be displayed with all of the other information. The table is the one with First Name and Last Name as the headers. Check the link below.
any ideas? i will appreciate any feedback. thanks.
you can also check the link http://uwn.betachitheta.org/ and enter 'nabeel' in the search box and submit it to see what i'm talking about.
nabeel