Jump to content

My search form... it "sort of" works. Please help.


aaricwon

Recommended Posts

I have a basic search form. When you go to the actual url www.bjjnews.org/problems/search.php it works just fine.

 

For some reeason when on another page I use      <? include 'search.php';?>

 

You type in what you want to search for and hit search and it just brings up the blank search page.

 

Any idea why?

 

the url for the search page: http://www.bjjnews.org/problems/search.php

the url for the page I want to include the search form on: http://www.bjjnews.org/problems

 

 

Link to comment
Share on other sites

Thanks! I tried what you posted and then a few other ways... no luck...

 

here is my code:

 

  <?php

// 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 problems1 " .
"WHERE id LIKE '%".$keywords[$i]."%'".
" OR field_1 LIKE '%".$keywords[$i]."%'" .
" OR field_2 LIKE '%".$keywords[$i]."%'" .
" OR field_3 LIKE '%".$keywords[$i]."%'" .
" OR field_4 LIKE '%".$keywords[$i]."%'" .
" OR field_5 LIKE '%".$keywords[$i]."%'" .
" OR field_6 LIKE '%".$keywords[$i]."%'" .
" OR field_7 LIKE '%".$keywords[$i]."%'" .
" ORDER BY field_2";
}

//Store the results in a variable or die if query fails
$result = mysql_query($query) or die(mysql_error());

}
if (isset ($_GET['id'])) {
    $id = $_GET['id'];
}
if ($search == NULL or $search == '%'){
} else {
//Count the rows retrived
$count = mysql_num_rows($result);
}

echo "<html>";
echo "<head>";
echo "<title>TRiD!UM Problem Orders</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 "<form name=\"searchform\" method=\"GET\" action="./>";
echo "<input type=\"text\" name=\"search\" size=\"15\" 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 "<FONT COLOR=\"red\">You searched for <b>";
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\"></font></b></center>";
} elseif ($search == '%'){
echo "<center><b><FONT COLOR=\"red\"></font></b></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
} 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
$row_color = ($row_count % 2) ? $color1 : $color2;
//table background color = row_color variable
echo "<center><table bgcolor=".$row_color." width=\"750\">";
echo "<tr>";
echo "<td width=\"120\"><b>".$row['field_1']."</b></td>";
echo "<td width=\"100\">".$row['field_2']."</td>";
echo "<td width=\"115\">".$row['field_3']."</td>";
echo "<td width=\"115\">".$row['field_4']."</td>";
echo "<td width=\"115\">".$row['field_5']."</td>";
echo "<td width=\"115\">".$row['field_6']."</td>";
echo "<td width=\"115\">".$row['field_7']."</td>";
echo "</tr>";
echo "</table></center>";
$row_count++;
//end while
}
//end if
}

echo "</body>";
echo "</html>";
if ($search == NULL or $search == '%') {
} else {
//clear memory
mysql_free_result($result);
}
?></div>
[code]

[/code]

Link to comment
Share on other sites

i have the same problem though i cant be bummed to get an editor :P, i just use notepad lol.

 

heres the revised code: (Note you forgot to escape a double quote (")

 

<?php

// 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 problems1 " .
	"WHERE id LIKE '%".$keywords[$i]."%'".
	" OR field_1 LIKE '%".$keywords[$i]."%'" .
	" OR field_2 LIKE '%".$keywords[$i]."%'" .
	" OR field_3 LIKE '%".$keywords[$i]."%'" .
	" OR field_4 LIKE '%".$keywords[$i]."%'" .
	" OR field_5 LIKE '%".$keywords[$i]."%'" .
	" OR field_6 LIKE '%".$keywords[$i]."%'" .
	" OR field_7 LIKE '%".$keywords[$i]."%'" .
	" ORDER BY field_2";
}

//Store the results in a variable or die if query fails
$result = mysql_query($query) or die(mysql_error());
}
if (isset ($_GET['id'])) {
    $id = $_GET['id'];
}
if ($search == NULL or $search == '%'){

} else {
//Count the rows retrived
$count = mysql_num_rows($result);
}

echo "<html>";
echo "<head>";
echo "<title>TRiD!UM Problem Orders</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 "<form name=\"searchform\" method=\"GET\" action=\"./\">"; // You had an unescaped double Quote here.
echo "<input type=\"text\" name=\"search\" size=\"15\" 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 "<FONT COLOR=\"red\">You searched for <b>";
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\"></font></b></center>"; // Do you not want to add you warning?
} elseif ($search == '%'){
echo "<center><b><FONT COLOR=\"red\"></font></b></center>"; // Do you not want to add you warning?
//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>
</center>";
//ELSE print the data in a table
} 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
	$row_color = ($row_count % 2) ? $color1 : $color2;
	//table background color = row_color variable
	echo "<center><table bgcolor=".$row_color." width=\"750\">";
	echo "<tr>";
	echo "<td width=\"120\"><b>".$row['field_1']."</b></td>";
	echo "<td width=\"100\">".$row['field_2']."</td>";
	echo "<td width=\"115\">".$row['field_3']."</td>";
	echo "<td width=\"115\">".$row['field_4']."</td>";
	echo "<td width=\"115\">".$row['field_5']."</td>";
	echo "<td width=\"115\">".$row['field_6']."</td>";
	echo "<td width=\"115\">".$row['field_7']."</td>";
	echo "</tr>";
	echo "</table></center>";
	$row_count++;
	//end while
}
//end if
}

echo "</body>";
echo "</html>";
if ($search == NULL or $search == '%') {

} else {
//clear memory
mysql_free_result($result);
}
?></div>

Link to comment
Share on other sites

lol i knew i would break someones script at some point, ok...

 

try this:

 

<?php

// 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 problems1 " .
	"WHERE id LIKE '%".$keywords[$i]."%'".
	" OR field_1 LIKE '%".$keywords[$i]."%'" .
	" OR field_2 LIKE '%".$keywords[$i]."%'" .
	" OR field_3 LIKE '%".$keywords[$i]."%'" .
	" OR field_4 LIKE '%".$keywords[$i]."%'" .
	" OR field_5 LIKE '%".$keywords[$i]."%'" .
	" OR field_6 LIKE '%".$keywords[$i]."%'" .
	" OR field_7 LIKE '%".$keywords[$i]."%'" .
	" ORDER BY field_2";
}

//Store the results in a variable or die if query fails
$result = mysql_query($query) or die(mysql_error());
}
if (isset ($_GET['id'])) {
    $id = $_GET['id'];
}
if ($search == NULL or $search == '%'){

} else {
//Count the rows retrived
$count = mysql_num_rows($result);
}

echo "<html>";
echo "<head>";
echo "<title>TRiD!UM Problem Orders</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 "<form name=\"searchform\" method=\"GET\" action=\"".htmlentities($_SERVER['PHP_SELF'])."\">"; // You had an unescaped double Quote here.
echo "<input type=\"text\" name=\"search\" size=\"15\" 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 "<FONT COLOR=\"red\">You searched for <b>";
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\"></font></b></center>"; // Do you not want to add you warning?
} elseif ($search == '%'){
echo "<center><b><FONT COLOR=\"red\"></font></b></center>"; // Do you not want to add you warning?
//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>
</center>";
//ELSE print the data in a table
} 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
	$row_color = ($row_count % 2) ? $color1 : $color2;
	//table background color = row_color variable
	echo "<center><table bgcolor=".$row_color." width=\"750\">";
	echo "<tr>";
	echo "<td width=\"120\"><b>".$row['field_1']."</b></td>";
	echo "<td width=\"100\">".$row['field_2']."</td>";
	echo "<td width=\"115\">".$row['field_3']."</td>";
	echo "<td width=\"115\">".$row['field_4']."</td>";
	echo "<td width=\"115\">".$row['field_5']."</td>";
	echo "<td width=\"115\">".$row['field_6']."</td>";
	echo "<td width=\"115\">".$row['field_7']."</td>";
	echo "</tr>";
	echo "</table></center>";
	$row_count++;
	//end while
}
//end if
}

echo "</body>";
echo "</html>";
if ($search == NULL or $search == '%') {

} else {
//clear memory
mysql_free_result($result);
}
?></div>

Link to comment
Share on other sites

on the page where you are including the search.php, the <form> tag is not set correctly on the search form.

 

(to quote from your source):

 

<form name="form" action="search.php" method="get">

needs to be

 

<form name="form" action="./displaytable_oracle.php" method="get">

 

are you sure your including the revised file?

Link to comment
Share on other sites

one last question... how can I get the search page that displays results to have the same header image as the other pages?

 

when you click search and view results, it is a plain page.

 

When you add the header image to the search page, it shows up twice on the pages you include the search.php

Link to comment
Share on other sites

ok, you should store the results from search.php into a variable instead of echoing it all out

 

then change your index file to echo that variable where the full table is, (if the variable is empty then show the full list).

 

then literally just include("search.php"); into your index file.

...........

 

if you cant figure it out give your current code for your index/search.php files and ill show you what i mean

 

Link to comment
Share on other sites

I feel bad for bugging you but... I can't figure it out.

 

search.php:

<?php
//Get variables from config.php to connect to mysql server
require 'config1.php';

// 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 problems1 " .
"WHERE id LIKE '%".$keywords[$i]."%'".
" OR field_1 LIKE '%".$keywords[$i]."%'" .
" OR field_2 LIKE '%".$keywords[$i]."%'" .
" OR field_3 LIKE '%".$keywords[$i]."%'" .
" OR field_4 LIKE '%".$keywords[$i]."%'" .
" OR field_5 LIKE '%".$keywords[$i]."%'" .
" OR field_6 LIKE '%".$keywords[$i]."%'" .
" OR field_7 LIKE '%".$keywords[$i]."%'" .
" ORDER BY field_2";
}

//Store the results in a variable or die if query fails
$result = mysql_query($query) or die(mysql_error());

}
if (isset ($_GET['id'])) {
    $id = $_GET['id'];
}
if ($search == NULL or $search == '%'){
} else {
//Count the rows retrived
$count = mysql_num_rows($result);
}

echo "<html>";
echo "<head>";
echo "<title>TRiD!UM Problem Orders</title>";
echo "</head>";
echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">";
echo "<center>";
echo "<form name=\"searchform\" method=\"GET\" action=\"".htmlentities($_SERVER['PHP_SELF'])."\">"; // You had an unescaped double Quote here.
echo "<input type=\"text\" name=\"search\" size=\"15\" 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 "<FONT COLOR=\"red\">You searched for <b>";
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\"></font></b></center>";
} elseif ($search == '%'){
echo "<center><b><FONT COLOR=\"red\"></font></b></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
} 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
$row_color = ($row_count % 2) ? $color1 : $color2;
//table background color = row_color variable
echo "<center><table bgcolor=".$row_color." width=\"750\">";
echo "<tr>";
echo "<td width=\"120\"><b>".$row['field_1']."</b></td>";
echo "<td width=\"100\">".$row['field_2']."</td>";
echo "<td width=\"115\">".$row['field_3']."</td>";
echo "<td width=\"115\">".$row['field_4']."</td>";
echo "<td width=\"115\">".$row['field_5']."</td>";
echo "<td width=\"115\">".$row['field_6']."</td>";
echo "<td width=\"115\">".$row['field_7']."</td>";
echo "</tr>";
echo "</table></center>";
$row_count++;
//end while
}
//end if
}

echo "</body>";
echo "</html>";
if ($search == NULL or $search == '%') {
} else {
//clear memory
mysql_free_result($result);
}
?></div>
[code]

[/code]

Link to comment
Share on other sites

code for index.php

 

<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<p align="center"><img src="imgs/world-bar.png" width="770" height="59" />
<form name="form" action="search.php" method="get">
  <div align="center">
    <p><a href="form.html" class="style1">Report a Problem Order</a></p>
    <?
  include 'search.php';
  ?>
    </p>
  </div>
</form>
<p align="center">Sort by: <a href="displaytable_date.php">Date</a>, <a href="displaytable_oracle.php">Oracle Order</a>, <a href="displaytable_customer.php">Customer</a>
, <a href="displaytable_who.php">Reported by</a><br>Edit/Update Info: <a href="http://www.bjjnews.org/problems/updates.php">Edit Problem Orders</a> , <a href="http://www.bjjnews.org/problems/delete.php">Delete Problem Orders</a>
<div align=center><strong><p>Sorted by: <u>DATE</u></strong><p></div>
  <?php

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');

$dbname = 'bjjnews_problemorders';
mysql_select_db($dbname);

$query  = "SELECT * FROM problems1 ORDER BY field_6 ASC";
$result = mysql_query($query);

echo "<table border='1' cellspacing='0'>
<tr>
<th bgcolor='FFFFCC'>Oracle Order</th>
<th bgcolor='FFFFCC'>Customer</th>
<th bgcolor='FFFFCC'>Customer PO</th>
<th bgcolor='FFFFCC'>Problem</th>
<th bgcolor='FFFFCC'>Reported by</th>
<th bgcolor='FFFFCC'>Date</th>
<th bgcolor='FFFFCC'>Status</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr bgcolor='CCCCCC'>";
  echo "<td>" . $row['field_1'] . "</td>";
  echo "<td>" . $row['field_2'] . "</td>";
    echo "<td>" . $row['field_3'] . "</td>";
  echo "<td>" . $row['field_4'] . "</td>";
    echo "<td>" . $row['field_5'] . "</td>";
  echo "<td>" . $row['field_6'] . "</td>";
    echo "<td>" . $row['field_7'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
?>
[code]

[/code]

Link to comment
Share on other sites

hehe, ok:

 

index.php:

<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<p align="center"><img src="imgs/world-bar.png" width="770" height="59" />
<form name="form" action="<?php echo(htmlentities($_SERVER['PHP_SELF'])); ?>" method="get">
  <div align="center">
    <p><a href="form.html" class="style1">Report a Problem Order</a></p>
    <?
  include 'search.php';
  ?>
    </p>
  </div>
</form>
<p align="center">Sort by: <a href="displaytable_date.php">Date</a>, <a href="displaytable_oracle.php">Oracle Order</a>, <a href="displaytable_customer.php">Customer</a>
, <a href="displaytable_who.php">Reported by</a><br>Edit/Update Info: <a href="http://www.bjjnews.org/problems/updates.php">Edit Problem Orders</a> , <a href="http://www.bjjnews.org/problems/delete.php">Delete Problem Orders</a>
<div align=center><strong><p>Sorted by: <u>DATE</u></strong><p></div>
  <?php


If($PAGE_RESULT != null && $search != NULL && $search != '%'){
echo($PAGE_RESULT);
}else{

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');

$dbname = 'bjjnews_problemorders';
mysql_select_db($dbname);

$query  = "SELECT * FROM problems1 ORDER BY field_6 ASC";
$result = mysql_query($query);

echo "<table border='1' cellspacing='0'>
<tr>
<th bgcolor='FFFFCC'>Oracle Order</th>
<th bgcolor='FFFFCC'>Customer</th>
<th bgcolor='FFFFCC'>Customer PO</th>
<th bgcolor='FFFFCC'>Problem</th>
<th bgcolor='FFFFCC'>Reported by</th>
<th bgcolor='FFFFCC'>Date</th>
<th bgcolor='FFFFCC'>Status</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr bgcolor='CCCCCC'>";
  echo "<td>" . $row['field_1'] . "</td>";
  echo "<td>" . $row['field_2'] . "</td>";
    echo "<td>" . $row['field_3'] . "</td>";
  echo "<td>" . $row['field_4'] . "</td>";
    echo "<td>" . $row['field_5'] . "</td>";
  echo "<td>" . $row['field_6'] . "</td>";
    echo "<td>" . $row['field_7'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
}
?>

 

and search.php:

<?php
//Get variables from config.php to connect to mysql server
require 'config1.php';

// 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 problems1 " .
"WHERE id LIKE '%".$keywords[$i]."%'".
" OR field_1 LIKE '%".$keywords[$i]."%'" .
" OR field_2 LIKE '%".$keywords[$i]."%'" .
" OR field_3 LIKE '%".$keywords[$i]."%'" .
" OR field_4 LIKE '%".$keywords[$i]."%'" .
" OR field_5 LIKE '%".$keywords[$i]."%'" .
" OR field_6 LIKE '%".$keywords[$i]."%'" .
" OR field_7 LIKE '%".$keywords[$i]."%'" .
" ORDER BY field_2";
}

//Store the results in a variable or die if query fails
$result = mysql_query($query) or die(mysql_error());

}
if (isset ($_GET['id'])) {
    $id = $_GET['id'];
}
if ($search == NULL or $search == '%'){
} else {
//Count the rows retrived
$count = mysql_num_rows($result);
}

$PAGE_RESULT =  "<html>";
$PAGE_RESULT .=  "<head>";
$PAGE_RESULT .=  "<title>TRiD!UM Problem Orders</title>";
$PAGE_RESULT .=  "</head>";
$PAGE_RESULT .=  "<body onLoad=\"self.focus();document.searchform.search.focus()\">";
$PAGE_RESULT .=  "<center>";
$PAGE_RESULT .=  "<form name=\"searchform\" method=\"GET\" action=\"".htmlentities($_SERVER['PHP_SELF'])."\">"; // You had an unescaped double Quote here.
$PAGE_RESULT .=  "<input type=\"text\" name=\"search\" size=\"15\" TABINDEX=\"1\" />";
$PAGE_RESULT .=  " <input type=\"submit\" value=\"Search\" />";
$PAGE_RESULT .=  "</form>";

//If search variable is null do nothing, else print it.
if ($search == NULL) {

} else {
$PAGE_RESULT .=  "<FONT COLOR=\"red\">You searched for <b>";
foreach($keywords as $value) {
	print "$value ";
}
$PAGE_RESULT .=  "</font></b>";
}
$PAGE_RESULT .=  "<p> </p>";
$PAGE_RESULT .=  "</center>";


//If users doesn't enter anything into search box tell them to.
if ($search == NULL){
$PAGE_RESULT .=  "<center><b><FONT COLOR=\"red\"></font></b></center>";
} elseif ($search == '%'){
$PAGE_RESULT .=  "<center><b><FONT COLOR=\"red\"></font></b></center>";
//If no results are returned print it
} elseif ($count <= 0){
$PAGE_RESULT .=  "<center><b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br /></center>";
//ELSE print the data in a table
} 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
$row_color = ($row_count % 2) ? $color1 : $color2;
//table background color = row_color variable
$PAGE_RESULT .=  "<center><table bgcolor=".$row_color." width=\"750\">";
$PAGE_RESULT .=  "<tr>";
$PAGE_RESULT .=  "<td width=\"120\"><b>".$row['field_1']."</b></td>";
$PAGE_RESULT .=  "<td width=\"100\">".$row['field_2']."</td>";
$PAGE_RESULT .=  "<td width=\"115\">".$row['field_3']."</td>";
$PAGE_RESULT .=  "<td width=\"115\">".$row['field_4']."</td>";
$PAGE_RESULT .=  "<td width=\"115\">".$row['field_5']."</td>";
$PAGE_RESULT .=  "<td width=\"115\">".$row['field_6']."</td>";
$PAGE_RESULT .=  "<td width=\"115\">".$row['field_7']."</td>";
$PAGE_RESULT .=  "</tr>";
$PAGE_RESULT .=  "</table></center>";
$row_count++;
//end while
}
//end if
}

$PAGE_RESULT .=  "</body>";
$PAGE_RESULT .=  "</html>";
if ($search == NULL or $search == '%') {
} else {
//clear memory
mysql_free_result($result);
}
?></div>

 

hope it works i did it quickly :P

Link to comment
Share on other sites

oops my mistake :P, turned too much into a variable hehe.

 

you do understand what ive done right? otherwise you wont learn :P

 

<?php
//Get variables from config.php to connect to mysql server
require 'config1.php';

// 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'];
$PAGE_RESULT = "";
}

//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 problems1 " .
"WHERE id LIKE '%".$keywords[$i]."%'".
" OR field_1 LIKE '%".$keywords[$i]."%'" .
" OR field_2 LIKE '%".$keywords[$i]."%'" .
" OR field_3 LIKE '%".$keywords[$i]."%'" .
" OR field_4 LIKE '%".$keywords[$i]."%'" .
" OR field_5 LIKE '%".$keywords[$i]."%'" .
" OR field_6 LIKE '%".$keywords[$i]."%'" .
" OR field_7 LIKE '%".$keywords[$i]."%'" .
" ORDER BY field_2";
}

//Store the results in a variable or die if query fails
$result = mysql_query($query) or die(mysql_error());

}
if (isset ($_GET['id'])) {
    $id = $_GET['id'];
}
if ($search == NULL or $search == '%'){
} else {
//Count the rows retrived
$count = mysql_num_rows($result);
}

// commented out some lines, you dont need them. may muck up your index page html structure
// $PAGE_RESULT =  "<html>";
// $PAGE_RESULT .=  "<head>";
// $PAGE_RESULT .=  "<title>TRiD!UM Problem Orders</title>";
// $PAGE_RESULT .=  "</head>";
// $PAGE_RESULT .=  "<body onLoad=\"self.focus();document.searchform.search.focus()\">";
// $PAGE_RESULT .=  "<center>";
echo  "<form name=\"searchform\" method=\"GET\" action=\"".htmlentities($_SERVER['PHP_SELF'])."\">";
echo  "<input type=\"text\" name=\"search\" size=\"15\" TABINDEX=\"1\" />";
echo  " <input type=\"submit\" value=\"Search\" />";
echo  "</form>";

//If search variable is null do nothing, else print it.
if ($search == NULL) {

} else {
$PAGE_RESULT .=  "<FONT COLOR=\"red\">You searched for <b>";
foreach($keywords as $value) {
	print "$value ";
}
$PAGE_RESULT .=  "</font></b>";
}
// $PAGE_RESULT .=  "<p> </p>";
// $PAGE_RESULT .=  "</center>";


//If users doesn't enter anything into search box tell them to.
if ($search == NULL){
$PAGE_RESULT .=  "<center><b><FONT COLOR=\"red\"></font></b></center>";
} elseif ($search == '%'){
$PAGE_RESULT .=  "<center><b><FONT COLOR=\"red\"></font></b></center>";
//If no results are returned print it
} elseif ($count <= 0){
$PAGE_RESULT .=  "<center><b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br /></center>";
//ELSE print the data in a table
} 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
$row_color = ($row_count % 2) ? $color1 : $color2;
//table background color = row_color variable
$PAGE_RESULT .=  "<center><table bgcolor=".$row_color." width=\"750\">";
$PAGE_RESULT .=  "<tr>";
$PAGE_RESULT .=  "<td width=\"120\"><b>".$row['field_1']."</b></td>";
$PAGE_RESULT .=  "<td width=\"100\">".$row['field_2']."</td>";
$PAGE_RESULT .=  "<td width=\"115\">".$row['field_3']."</td>";
$PAGE_RESULT .=  "<td width=\"115\">".$row['field_4']."</td>";
$PAGE_RESULT .=  "<td width=\"115\">".$row['field_5']."</td>";
$PAGE_RESULT .=  "<td width=\"115\">".$row['field_6']."</td>";
$PAGE_RESULT .=  "<td width=\"115\">".$row['field_7']."</td>";
$PAGE_RESULT .=  "</tr>";
$PAGE_RESULT .=  "</table></center>";
$row_count++;
//end while
}
//end if
}

// $PAGE_RESULT .=  "</body>";
// $PAGE_RESULT .=  "</html>";
if ($search == NULL or $search == '%') {
} else {
//clear memory
mysql_free_result($result);
}
?></div>

 

see how that looks for now.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.