Jump to content

Misalignment after duplicated codes


genzedu777

Recommended Posts

Hi,

 

I have a question. Currently, when I retrieve the records in my zone 'North', there is no misalignment.

 

However when I tried to copy the same coding to make up zone 'West', the alignment went off? May I know what is the reason? Any advice to align it properly.

 

Attached is the picture of my example

 

 

 

<div id ="location">

<input name="zone[]" type="checkbox" id="1" value="1">

    <label for="1">North</label><br />

 

<?php

$dbc = mysqli_connect('localhost', 'aliendatabase', '1234567', 'aliendatabase')

or die(mysqli_error());

$query = ("SELECT * FROM tutor_preferred_district ORDER BY district_id ASC");

$sql = mysqli_query($dbc, $query)

or die(mysqli_error());

echo'<table><tr>'; // Start your table outside the loop... and your first row

$count = 0; // Start your counter

while($data = mysqli_fetch_array($sql)) {

/* Check to see whether or not this is a *new* row

If it is, then end the previous and start the next and restart the counter.

*/

            if ($count % 3 == 0) {

echo "</tr><tr>"; $count = 0;

}

echo '<td><input name="district[]" type="checkbox" id="'.$data['district_id'].'" value="'.$data['district_id'].'">';

echo '<label for="'.$data['district_id'].'">'.$data['district_name'].'</label></td>';

$count++; //Increment the count

      }

  echo '</tr></table><br />'; //Close your last row and your table, outside the loop

?>

 

 

<input name="zone[]" type="checkbox" id="2" value="2">

    <label for="2">West</label><br />

<?php

$dbc = mysqli_connect('localhost', 'aliendatabase', '1234567', 'aliendatabase')

or die(mysqli_error());

$query = ("SELECT * FROM tutor_preferred_district ORDER BY district_id ASC");

$sql = mysqli_query($dbc, $query)

or die(mysqli_error());

echo'<table><tr>'; // Start your table outside the loop... and your first row

$count = 0; // Start your counter

while($data = mysqli_fetch_array($sql)) {

/* Check to see whether or not this is a *new* row

If it is, then end the previous and start the next and restart the counter.

*/

            if ($count % 3 == 0) {

echo "</tr><tr>"; $count = 0;

}

echo '<td><input name="district[]" type="checkbox" id="'.$data['district_id'].'" value="'.$data['district_id'].'">';

echo '<label for="'.$data['district_id'].'">'.$data['district_name'].'</label></td>';

$count++; //Increment the count

      }

  echo '</tr></table>'; //Close your last row and your table, outside the loop

?>

</div>

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/215988-misalignment-after-duplicated-codes/
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.