Jump to content

Stop Table Headers Repeating


Smee

Recommended Posts

have a working search script as show below and wondering why my headers keep repeating?

 


<?php 

// This script allows us to search our database

require_once ('./includes/config.inc.php');

$page_title = 'Search';

include ('./includes/header.html');

$error = false;

if (isset($_POST['submit'])) {

if(isset($_GET['go'])){ 

require_once ('../mysql_connect.php');

$error = false;
if (preg_match ('/^[[:alnum:]]{4,20}$/i', stripslashes(trim($_POST['post_code'])))) {
$pc = $_POST['post_code'];

} else {
      
   echo '<p><font color ="red" size="+1"> Please enter the first 4 letters of your Post Code!</font></p>';
   $error = true;
   
}

$ts = $_POST['team_supported'];

if (!$error) {
      
  //-query  the database table 

      $query = "SELECT first_name, last_name, email, post_code, team_supported FROM users WHERE post_code LIKE '%" . $pc .  "%' AND team_supported LIKE '%" . $ts .  "%'"; 

  //-run  the query against the mysql query function

      $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error());

  //-create  while loop and loop through result set 

  while($row=mysql_fetch_array($result)){ 
          $fn = $row['first_name'];
          $ln = $row['last_name'];
          $em = $row['email'];
          $pc = $row['post_code'];
		  $ts = $row['team_supported'];

?>
	  
<table width="600" height="100" border="0" />
  <tr>
    <th scope="col">First Name</th>
    <th scope="col">Last Name</th>
    <th scope="col">E Mail</th>
    <th scope="col">Post Code</th>
    <th scope="col">Team Supported</th>
        
  </tr>
  <tr>
    <td><?php echo "<p>" .$fn . "</p>"; ?></td>
    <td><?php echo "<p>" .$ln . "</p>"; ?></td>
    <td><?php echo "<p>" .$em . "</p>"; ?></td>
    <td><?php echo "<p>" .$pc . "</p>"; ?></td>
    <td><?php echo "<p>" .$ts . "</p>"; ?></td>
  </tr>
</table>
		  
<?php
   
  } 
  } 
  else{ 
  echo  "<p>Please enter a search query</p>"; 
  } 
  }
}	  

?> 

<h1> Search </h1>

<form action="search.php?go" method="post" />

<p class="post_code"><label> Post Code: </label>
<input type="text" name="post_code" maxlength="40" "/>

<p class="post_code"><label> Team Supported: </label>
<input type="text" name="team_supported" maxlength="40" />

<p class="submit">
<input type="submit" name="submit" value="Search" />
            
</form>

<?php
include ('./includes/footer.html');
?>

Link to comment
https://forums.phpfreaks.com/topic/200237-stop-table-headers-repeating/
Share on other sites

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.