aaricwon Posted February 18, 2008 Share Posted February 18, 2008 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 Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 Also, I just want to say thanks to everyone on here. This forum is great and I have learned ALOT from it. I knoq I have a LONG way to go but I feel I am learning quickly with all of the help I get here. Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 on your search.php page where you put "<form action='search.php'...." change to: <form action='./' .... Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 i see your having trouble, post your code from search.php here if you need further help Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 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] Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 sorry to be a pain but on your last post could you click "modify" and add [ code ] tags before and after your script? you < b > tags are being interpreted by this forum Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 I'm sorry. Done Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 np, is this the code with Parse error: syntax error, unexpected '/' in /home/bjjnews/public_html/problems/search.php on line 69 by any chance? Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 Can you suggest a text editor? I only have notepad here so it is hard counting lines Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 i have the same problem though i cant be bummed to get an editor , 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> Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 also FYI: you can use != operator to check if a variable is NOT equal to another. (te get rid of those unused IF statements) Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 Still not working. Actually when I started, you could go to the search.php and it worked fine, it just didn't work on the index.php where I included it. Now it works on neither. Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 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> Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 lol. Thanks for helping. I used the code you just gave but still not having luck. Check it out, if you go to the actual search page, it works great! If you go to another page like http://www.bjjnews.org/problems/displaytable_oracle.php I have no luck Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 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? Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 AHH! I got it. THANKS SOOOOO MUCH!! Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 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 Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 could you give me a link to show me whats going on? Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 sure. http://www.bjjnews.org/problems/index.php try to search. works great. I just want the results to look like the rest of it as far as having a header image etc. Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 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 Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 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] Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 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] Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 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 Quote Link to comment Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 lol not yet. Thanks again though!!! check it (search isn't there?) http://www.bjjnews.org/problems/ Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 oops my mistake , turned too much into a variable hehe. you do understand what ive done right? otherwise you wont learn <?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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.