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\">&nbsp;".$row['Name']."</font></td>";
echo "<td width=\"50%\" align=\"left\"><font face=\"Times New Roman\" color=\"blue\">&nbsp;".$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>&nbsp;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\">&nbsp;".$row['Roll_No']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b>&nbsp;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\">&nbsp;".$row['Name']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b>&nbsp;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\">&nbsp;".$row['F Name']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b>&nbsp;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\">&nbsp;".$row['Hindi']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b>&nbsp;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\">&nbsp;".$row['English']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b>&nbsp;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\">&nbsp;".$row['Science']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b>&nbsp;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\">&nbsp;".$row['Maths']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b>&nbsp;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\">&nbsp;".$row['Social Science']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b>&nbsp;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\">&nbsp;".$row['Sanskrit']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b>&nbsp;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\">&nbsp;".$row['Total']."</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td width+\"222\" align=\"left\"><font face=\"Times New Roman\"><b>&nbsp;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\">&nbsp;".$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........

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.......

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

you can find this query on http://www.kuchamancity.com/8thResult.php
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........

Here is one solution:

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.......

//Set the MySQL query
if ($search == NULL or $search == '%'){
} else {
$where_addin = ''; //this will be the added WHERE statement

for ($i=0; $i<count($keywords); $i++) {
if ($i == 0) {  //no OR if its the first variable 
$where_addin .= "WHERE Roll_No LIKE '%".$keywords[$i]."%'"." OR Name LIKE '%".$keywords[$i]."%' ";
} else {
$where_addin .= "OR Roll_No LIKE '%".$keywords[$i]."%'"." OR Name LIKE '%".$keywords[$i]."%' ";
}

$query = "SELECT * FROM table 
 $where_addin
 ORDER BY Roll_No";

Thanx frnd for Helping me but This Code does not work.... It;s Does Not Show Maney Data in a Hyperlink View.... Plz Give me Approx Code.

Sorry Frnd But Your Given Code Does Not Eork Plz Help me.....
Someone Plz Help Me...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.