Weird table display in while loop -- HELP

Hi,

I have a search form that displays the results properly but for some reason the table displayed in the while loop is all weird. Basically when I do a search, lets say I have 14 results – the output displays 14 empty rows and then another 14 rows with my actual results.

Not sure what I am doing wrong, hope someone can point me in the right direction. There is link to a screenshot of the results

my code



<?php

          $searchform = true;

          if (isset($_GET['search'])) {
          require('connect.php');

          $search_q_number= $_GET['question_number'];
          $search_q_en = $_GET['actual_question'];
          $search_a_en = $_GET['actual_answer'];
          $search_type1 = $_GET['type1'];
          $search_type2 = $_GET['type2'];
          $search_product_code = $_GET['product_code'];

          $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
          $query = "SELECT Question_Number, Question_EN, Answer_EN, Type1, Type2,
Product_Code FROM table3 WHERE Question_Number like '%$search_q_number%'
and Question_EN like '%$search_q_en%' and Answer_EN like '%$search_a_en%'
and Type1 like'%$search_type1%' and Type2 like '%$search_type2%' and
Product_Code like '%$search_product_code%'";

          $result = mysqli_query($dbc, $query);

          if (!$result) {
                             printf("query error : <br/> %s\
", mysqli_error($dbc));
                   }
          $searchform = false;

          echo '<div align="center">';
          echo '<table border="0" cellpadding="2" cellspacing="0" align="center"
width="100%">';
          echo '<tr align="center" width="100%" >';
          echo '<td><b>ID #</b></td>
          <td><b>Question Number</b></td>
          <td><b>Question English</b></td>
          <td><b>Question French</b></td>
          <td><b>Type 1</b></td>
          <td><b>Type 2</b></td>
          <td><b>Priority</b></td>
          <td><b>Answer English</b></td>
          <td><b>Answer French</b></td>
          <td><b>Product Code</b></td>
          ';
          echo '</tr>';
          echo '<br/></div>';

          //number of results
          $row_cnt = mysqli_num_rows($result);
          echo '<br/>';
          printf("<strong>There are a total of " . $row_cnt ." items matching");
          echo '</strong><br/>';


          while ($row = mysqli_fetch_assoc($result)) {
          echo "<tr bgcolor='#DAD7D7'>";

          echo '<td valign="top" >' . $row['log'] . '</td>';
          echo '<td valign="top" >' . $row['Question_Number'] . '</td>';
          echo '<td valign="top" >' . $row['Question_EN'] . '</td>';
          echo '<td valign="top" >' . $row['Question_FR'] . '</td>';
          echo '<td valign="top" >' . $row['Type1'] . '</td>';
          echo '<td valign="top" >' . $row['Type2'] . '</td>';
          echo '<td valign="top" >' . $row['Priority'] . '</td>';
          echo '<td valign="top" >' . $row['Answer_EN'] . '</td>';
          echo '<td valign="top" >' . $row['Answer_FR'] . '</td>';
          echo '<td valign="top" >' . $row['Product_Code'] . '</td>';
          echo '</tr>';
          }

          mysqli_close($dbc);
          exit();
          }

          if ($searchform) {
          require('searchform.php');
          }

?>

Any ideas???

Hi,

It is hard for me to see the code because I,m using a phone but you look to have missed the ending </table> tag off this can mess with your table layouts.

A lot of ending </td> are missing too in one section, validate the HTML and this might help fix the prob

Hi thanks for the replies.

Not sure how I missed the ending table tag but it did not make any difference, still get the same result.
As far as missing </td> tags … where? I don’t see any

Any other ideas??

It is the td’s in the first row, there is also a non closed div tag, and the br tags in the middle of 2 table rows which should be changed into a tr td and use the Colspan attribute

Thanks
Got it working
:slight_smile: