Current location: Hot Scripts Forums » Programming Languages » PHP » were do u put a search engine script on a html table


were do u put a search engine script on a html table

Reply
  #1 (permalink)  
Old 01-06-10, 10:39 AM
balamberas balamberas is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
were do u put a search engine script on a html table

I need some help with this script. its working fine but what do i do if i want to insert it within a html script. I have tried to but it between the <head> tags but dont get the result i want, pls help.

PHP Code:



<?php
 
include ('connect.php');
 
error_reporting(E_ALL);
ini_set('display_errors''1');
 
$submit $_GET['submit'];
$search $_GET['search'];
$x=0;
$construct='';
$foundnum=0;  
 
if (!
$submit)
   
  echo 
"you didnt submit a keyword.";  
 
else
 
{
 
if (
strlen($search)<=2)
 
   echo 
"search term to short.";
 else  
{
  echo 
" You searched for <b>$search</b><hr size='1'>";
 
  
//connect to our database
 
 
$search_exploded explode(" ",$search);
 
 
 foreach(
$search_exploded as $search_each)
 
{
 
// construct query
 
$x++;
if (
$x==1)
    
$construct .= " location LIKE '%$search_each%'";  
    else
    
$construct .= " OR location LIKE '%$search_each%'";
     
      }
 
   
// echo out construct
   
 
$construct "SELECT * FROM flats WHERE $construct";
 
$run mysql_query($construct);
 
$foundnum mysql_num_rows($run);
 
 
if (
$foundnum==0)
  echo 
"No results found.";
else
{
   echo 
"$foundnum result found!<p>";
 
 while (
$runrows mysql_fetch_assoc($run))
 
{
 
// get data
 
   
$select $runrows['type'];
   
$title $runrows['title'];
   
$location $runrows['location'];
   
$rent $runrows['rent'];
   
$description $runrows['description'];
   
$contactEmail $runrows['contactEmail'];
   
$number $runrows['number'];
 
echo 
"
 
    
$title
    <br>
    
$select
    <br>
    
$rent
    <br>
    
$location
    <br>
    
$description
    <br>
    
$contactEmail
    <br>
    
$number
   <hr>"
;
 
}      
 
 
      }
    }
  }
 
 
?>
Reply With Quote
  #2 (permalink)  
Old 01-06-10, 01:40 PM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
I assume you create the form and database that 'feeds' this script.

Option1:
Put it where ever you want in the page (where you want the output to show) and rename the page to (pagename).php

Option2:
Save this as a .php and use an IFRAME to include it in the page

Option3:
Change .htaccess so that you can run php from within .html / .htm
__________________
This post was created with 100% recycled electrons.
Reply With Quote
  #3 (permalink)  
Old 01-06-10, 03:03 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Put it all on one page.
Something like this:
PHP Code:

<?php
if(!empty($_POST["submit"]))
{
 
$search = empty($_POST['search']) ? "" $_POST['search'];
 
$x=0;
 
$construct='';
 
$foundnum=0;
 if(!
$search){$msg "You didnt submit a keyword.<p>";$c "#f00";}
 else
 {
  if(
strlen($search)<=2){$msg "Search term to short.<p>";$c "#f00";}
  else
  {
   
$msg "You searched for <b>$search</b><p>";
   
$c "#00f";
   
$search_exploded explode(" ",$search);
   foreach(
$search_exploded as $search_each)
   {
    
$x++;
    if(
$x==1){$construct .= " location LIKE '%$search_each%'";}
    else{
$construct .= " OR location LIKE '%$search_each%'";}
    }
   include (
'connect.php');
   
$construct "SELECT * FROM flats WHERE $construct";
   
$run mysql_query($construct);
   
$foundnum mysql_num_rows($run);
   if(
$foundnum==0){$msg "No results found.";}
   else
   {
    
$msg2 "$foundnum result found!<p>";
    
$results "";
    while (
$runrows mysql_fetch_assoc($run))
    {
     
// get data
     
$select $runrows['type'];
     
$title $runrows['title'];
     
$location $runrows['location'];
     
$rent $runrows['rent'];
     
$description $runrows['description'];
     
$contactEmail $runrows['contactEmail'];
     
$number $runrows['number'];
     
$results .= "<table>
                   <tr>
                    <td>
$title</td>
                   </tr>
                   <tr>
                    <td>
$select</td>
                   </tr>
                   <tr>
                    <td>
$rent</td>
                   </tr>
                   <tr>
                    <td>
$location</td>
                   </tr>
                   <tr>
                    <td>
$description</td>
                   </tr>
                   <tr>
                    <td>
$contactEmail</td>
                   </tr>
                   <tr>
                    <td>
$number</td>
                   </tr>
                   <tr>
                    <td><hr></td>
                   </tr>
                  </table>"
;
     }
    }
   }
  }
 }
?>
<html>
<head>
</head>
<body>
<div style='float:left;'>
 <div style="color:<?php echo $c?>;font-size:20px;"><b><?php echo $msg?></b></div>
 <form action="#" method="post">
  Input key word(s): <input type="text" name="search"><br />
  <input type="submit" name="submit" value="Submit">
 </form>
</div>
<div style="float:left;margin-left:30px;"><?php echo "<span style='color:#00f;'>$msg2</span><p>$results"?></div>
</body>
</html>
And make sure the page has a .php extension.
__________________
Jerry Broughton

Last edited by job0107; 01-06-10 at 03:07 PM.
Reply With Quote
  #4 (permalink)  
Old 01-06-10, 03:43 PM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
That is not correct, if you just put the code on top of the page in this way (even a .php page) then the output will be prior to the <html> <head> and <body> tags. The code should be inserted where the output is wanted.

and yes ... you can ensure that the page has a .php extension, however if it is an existing page then you might not want to change the page extension. In that case use one of the other options (see my original post)
__________________
This post was created with 100% recycled electrons.
Reply With Quote
  #5 (permalink)  
Old 01-06-10, 05:37 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
Originally Posted by ruteckycs View Post
That is not correct, if you just put the code on top of the page in this way (even a .php page) then the output will be prior to the <html> <head> and <body> tags. The code should be inserted where the output is wanted.

and yes ... you can ensure that the page has a .php extension, however if it is an existing page then you might not want to change the page extension. In that case use one of the other options (see my original post)
I don't mean to rain on your parade,
but if you knew anything about PHP,
you would see that my code not only works,
but I can use the stored variables anywhere in my HTML.
__________________
Jerry Broughton
Reply With Quote
  #6 (permalink)  
Old 01-06-10, 07:12 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by ruteckycs View Post
That is not correct, if you just put the code on top of the page in this way (even a .php page) then the output will be prior to the <html> <head> and <body> tags. The code should be inserted where the output is wanted.
Actually, all of Job0107's code runs before the page is printed, and the output is stored in the variable "$results". That variable could be placed anywhere in the page just by printing it out with <?php echo $results ?>.

I often do the same sort of thing when I want the result to be able to be moved around or placed in different areas. If you have a lot of code to run then it may delay the page output slightly, but it's better than printing out part of the page, then seeing a pause as the code runs, and then seeing the rest of the page appear.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]

Last edited by job0107; 01-07-10 at 04:46 PM.
Reply With Quote
  #7 (permalink)  
Old 01-06-10, 08:41 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
There are lots of different coding styles. I like job0107's approach, too.
Reply With Quote
  #8 (permalink)  
Old 01-06-10, 09:10 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Thank you, I am flattered.
__________________
Jerry Broughton
Reply With Quote
  #9 (permalink)  
Old 01-06-10, 09:58 PM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
Oh sorry Job, I do that as well. I didnt actually read your script. I had assumed that you just pasted the OP's code on top of a page.

But hey thanks for the smart *** comment .... if you knew anything ... glad to see that we have maturity in this forum .. especially from someone who is suppose to represent the forum community,
__________________
This post was created with 100% recycled electrons.
Reply With Quote
  #10 (permalink)  
Old 01-07-10, 08:05 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
Originally Posted by ruteckycs View Post
Oh sorry Job, I do that as well. I didnt actually read your script. I had assumed that you just pasted the OP's code on top of a page.

But hey thanks for the smart *** comment .... if you knew anything ... glad to see that we have maturity in this forum .. especially from someone who is suppose to represent the forum community,
I am also sorry if I rattled your cage a little.
I do not have much tolerance for programmers that do not examine the code before speaking.
But I am working on that.
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Search Engine Optimization Tools NameWolf General Advertisements 0 03-31-05 06:44 PM
get the table elements from other page using a background search script poison~IVY JavaScript 1 03-21-05 10:08 AM
SEO Expert Available nakulgoyal Job Offers & Assistance 2 08-14-04 12:38 PM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 08:06 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.