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

you can put it outside the html tag, just above the <html> tag

Member Avatar for diafol

you can put it outside the html tag, just above the <html> tag

If you do that all the output is placed above the <html> - which is not right - it'll fail validation and possibly mess up the page.
It may help if the code just gets the info to display and then you just echo the output in the appropriate place on the page. Place the code above the DTD.

include ('connect.php');
 error_reporting(E_ALL);
 ini_set('display_errors', '1');

$output = ''; 

...(rest of code)...

You need to do this for the echo statements:

$output .= "you didnt submit a keyword.";  

  $output .= "search term to short.";

  $output .= " You searched for <b>$search</b><hr size='1'>";

  $output .= "No results found.";

  $output .=  "$foundnum result found!<p>";
 
  $output .= "$title<br />$select<br />$rent<br />$location<br />$description<br />$contactEmail<br />$number<hr />";

Then in the appropriate place in the page, do this:

<?php echo $output;?>

oh sorry i miss to put a block... to prevent it from outputing... put the code inside the a conditional statement... that it will be outputed unless the search button is clicked

<?php

if(isset($_GET['btnsearch'])){
// all your search code here
}

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