Hi All,
I Have Some Problem with my PHP Searching Code...
I Want to Create Hyperlink of Multipul Data for Ex. :- a user Found example if this query have maney data this show as hyperlink view....
i am using this code.......
<?php
/**************************************************************************************
* Main Search Page - search.php
* Author: Your Name <user@something.com>
* This file searches the database
**************************************************************************************/
//Get variables from config.php to connect to mysql server
$dbhost='localhost';
$dbusername='user';
$dbuserpass='password';
$dbname = 'dbname';
// connect to the mysql database server.
mysql_connect ($dbhost, $dbusername, $dbuserpass);
//select the database
mysql_select_db($dbname) or die('Cannot select database');
//search variable = data in search box or url
if(isset($_GET['search']))
{
$search = $_GET['search'];
}
//trim whitespace from variable
$search = trim($search);
$search = preg_replace('/\s+/', ' ', $search);
//seperate multiple keywords into array space delimited
$keywords = explode(" ", $search);
//Clean empty arrays so they don't get every row as result
$keywords = array_diff($keywords, array(""));
//Set the MySQL query
if ($search == NULL or $search == '%'){
} else {
for ($i=0; $i<count($keywords); $i++) {
$query = "SELECT * FROM table " .
"WHERE Roll_No LIKE '%".$keywords[$i]."%'".
" OR Name LIKE '%".$keywords[$i]."%'" .
" ORDER BY Roll_No";
}
//Store the results in a variable or die if query fails
$result = mysql_query($query) or die(mysql_error());
}
if ($search == NULL or $search == '%'){
} else {
//Count the rows retrived
$count = mysql_num_rows($result);
}
echo "<html>";
echo "<head>";
echo "<title>Your Title Here</title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />";
echo "</head>";
echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">";
echo "<center>";
echo "<br /><form name=\"searchform\" method=\"GET\" action=\"8thResult.php\">";
echo "<font face=\"Times New Roman\"><b>Enter Roll No or Name : </b></font>";
echo "<input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" />";
echo " <input type=\"submit\" value=\"Search\" />";
echo "</form>";
//If search variable is null do nothing, else print it.
if ($search == NULL) {
} else {
echo "You searched for : <b><FONT COLOR=\"blue\">";
foreach($keywords as $value) {
print "$value ";
}
echo "</font></b>";
}
echo "<p> </p>";
echo "</center>";
//If users doesn't enter anything into search box tell them to.
if ($search == NULL){
echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>";
} elseif ($search == '%'){
echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>";
//If no results are returned print it
} elseif ($count <= 0){
echo "<center><b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br /></center>";
//ELSE print the data in a table
} elseif ($count > 1){
echo "<div align=\"center\">";
echo "<table border=\"1\" style=\"border-collapse: collapse\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"black\" width=\"450\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "<p align=\"center\">Name</td>";
echo "<td width=\"50%\">";
echo "<p align=\"center\">Roll No</td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"50%\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['Name']."</font></td>";
echo "<td width=\"50%\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['Roll_No']."</font></td>";
echo "</tr>";
echo "</table>";
echo "</div>";
} else {
//Colors for alternation of row color on results table
$color1 = "#d5d5d5";
$color2 = "#e5e5e5";
//While there are rows, print it.
while($row = mysql_fetch_array($result))
{
//Row color alternates for each row
//table background color = row_color variable
echo "<div align\"center\">";
echo "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"black\" width=\"450\">";
echo "<tr>";
echo "<td>";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"black\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"100%\">";
echo "<p align=\"center\"><font color=\"Red\"><b>DIET, Kuchaman City (Nagaur)</b></font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"100%\">";
echo "<p align=\"center\"><font color=\"Red\"><b>8 Board Result 2008</b></font></td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<table border=\"1\" style=\"border-collapse: collapse\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"black\" width=\"450\">";
echo "<tr>";
echo "<td width=\"222\" align=\"left\"><font face=\"Times New Roman\"><b> Roll No</b></font></td>";
echo "<td width=\"15\" align=\"center\"><b>:</b></td>";
echo "<td width=\"509\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['Roll_No']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b> Name</b></font></td>";
echo "<td width=\"15\" align=\"center\"><b>:</b></td>";
echo "<td width=\"509\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['Name']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b> Father Name</b></font></td>";
echo "<td width=\"15\" align=\"center\"><b>:</b></td>";
echo "<td width=\"509\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['F Name']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b> Hindi</b></font></td>";
echo "<td width=\"15\" align=\"center\"><b>:</b></td>";
echo "<td width=\"509\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['Hindi']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b> English</b></font></td>";
echo "<td width=\"15\" align=\"center\"><b>:</b></td>";
echo "<td width=\"509\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['English']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b> Science</b></font></td>";
echo "<td width=\"15\" align=\"center\"><b>:</b></td>";
echo "<td width=\"509\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['Science']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b> Maths</b></font></td>";
echo "<td width=\"15\" align=\"center\"><b>:</b></td>";
echo "<td width=\"509\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['Maths']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b> Social Science</b></font></td>";
echo "<td width=\"15\" align=\"center\"><b>:</b></td>";
echo "<td width=\"509\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['Social Science']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b> Sanskrit</b></font></td>";
echo "<td width=\"15\" align=\"center\"><b>:</b></td>";
echo "<td width=\"509\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['Sanskrit']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b> Total</b></font></td>";
echo "<td width=\"15\" align=\"center\"><b>:</b></td>";
echo "<td width=\"509\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['Total']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b> Percentage</b></font></td>";
echo "<td width=\"15\" align=\"center\"><b>:</b></td>";
echo "<td width=\"509\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\"> ".$row['Per']."</font></td>";
echo "</tr>";
echo "</table>";
echo "</div>";
$row_count++;
//end while
}
//end if
}
echo "</body>";
echo "</html>";
if ($search == NULL or $search == '%') {
} else {
//clear memory
mysql_free_result($result);
}
?>
you can find this query on [link]www.kuchamancity.com/8thResult.php[/link]
plz enter 10000 to display result but when i enter Hemant it does not display any result.. because hemant query having 2 Data.......
plz help me........