Jump to content

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


balamberas

Recommended Posts

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

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

}      


      }
    }
  }


?>

sorry i should have been more clear. I have a link i.e

www.domain-name.com/link.php

 

link.php is made with html and some php codes. I want to put the search engine script within the html codes but dont know were to put it. i have tried the between the <head> tags. with no success

 

 

Hi and thanks Marcus,

 

I have one more question though. I have a pagination script for the main page and i would like to have pagination for the search result too. How do i make the record_count follow the search result?

 

<?php
include ("connect.php");
$per_page = 20;
$start = $_GET ['start'];
$record_count = mysql_num_rows (mysql_query("SELECT * FROM flats "));
$max_pages = $record_count / $per_page; // may come out as a decimal

if(!$start){$start = 0;}
$get = mysql_query("SELECT * FROM flats ORDER BY date_posted DESC LIMIT $start, $per_page");

    $prev = $start - $per_page;
    $next = $start + $per_page;
    while ($row = mysql_fetch_assoc($get))
    {
     // get data
     $select= $row['type'];
     $title= $row['title'];
     $location= $row['location'];
     $rent = $row["rent"];
     echo "<tr class='row_style_tr'>
            <td class='row_style_td'><b>$title</b></td>
            <td class='row_style_td'>$select</td>
            <td class='row_style_td'>$rent</td>
            <td class='row_style_td'>$location</td>
           </tr>";
     }

      if($start>0){
      echo "<a href='search.php?start=$prev'> Prev </a>";}
      $i=1;
      for ($x=0;$x<$record_count;$x=$x+$per_page)
      {
       if($start!=$x){
       echo "<a href='search.php?start=$x'>$i | </a>";
      }
       else{
      echo "<a href='search.php?start=$x'><b> $i | </b></a>";}
       $i++;
       }
      if($start<$record_count-$per_page){echo "<a href='search.php?start=$next'> Next </a>";}
      ?>

Archived

This topic is now archived and is closed to further replies.

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