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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.