Smee Posted April 30, 2010 Share Posted April 30, 2010 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 More sharing options...
andrewgauger Posted April 30, 2010 Share Posted April 30, 2010 try include_once ('./includes/header.html'); Link to comment https://forums.phpfreaks.com/topic/200237-stop-table-headers-repeating/#findComment-1050819 Share on other sites More sharing options...
PFMaBiSmAd Posted April 30, 2010 Share Posted April 30, 2010 ALL your html table code is inside of the while(){} loop. You would want to only put the portion of the html table code for the repeating table-rows inside of the while(){} loop. Link to comment https://forums.phpfreaks.com/topic/200237-stop-table-headers-repeating/#findComment-1050820 Share on other sites More sharing options...
Smee Posted April 30, 2010 Author Share Posted April 30, 2010 Thanks PFMaBiSmAd, I have played around but seem to only get a duplicate of my /include/hdear.html after the form and one record showing with two table headers... (very strange?!). I dont suppose you could change my code to show what you mean? Thanks alot Link to comment https://forums.phpfreaks.com/topic/200237-stop-table-headers-repeating/#findComment-1050823 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.