Unwanted output from my query

Jazzy 1012
Jazzy 1012 used Ask the Experts™
on
require "../connection.php";
$result= mysqli_query($conn,"SELECT * FROM Users WHERE email = '$email'");
$row = mysqli_fetch_row($result);
$firstname = $row[1];
$zip = $row[6];

$query="select * from Zip WHERE zip = '$zip'";
$result2 = mysqli_query($conn,$query);
$counter = 0;
while ($row2 = mysqli_fetch_row($result2))
{
	$counter++;
	$ids= $row2[1];

	$query1= "SELECT * from Zones LEFT JOIN both ON Zones.id = both.zone_id LEFT JOIN Windows ON both.window_id = Windows.id where Zones.id = '".$ids ."'";
	$result3 = mysqli_query($conn,$query1);
	$row3 = mysqli_fetch_row($result3);
	$dayt = $row3[9];
	$times = $row3[10];

?>
<form>
<table class="table table-bordered">
<thead>
      <tr>
    <th class="thheader">Monday</th>
    <th class="thheader">Tuesday</th>
    <th class="thheader">Wednesday</th>
    <th class="thheader">Thursday</th>
    <th class="thheader">Friday</th>
    </tr>
    </thead>
    <tr>
      <td>
      <center>
      <?php if($dayt == '1'){ ?>
      	<input type="checkbox" class="colour-button cbb" name="v1" value="10 - 12" id="btn112<?php echo $counter;?>" /><label for="btn112<?php echo $counter;?>"> <i class="fa fa-check-circle hide12" id="chk-btn112<?php echo $counter;?>"></i>  <?php echo $times;?></label>

      <?php }?>
      </center>
      </td>
      <td>
      <center>
      <?php if($dayt == '2'){?>
      <input type="checkbox" class="colour-button cbb1" name="v1" value="10 - 12" id="btn1012<?php echo $counter;?>" /><label for="btn1012<?php echo $counter;?>"> <i class="fa fa-check-circle hide13" id="chk-btn1012<?php echo $counter;?>"></i>  <?php echo $times;?></label>
      <?php }?>  
      </center>
      </td>
      <td>
      <center>
      <?php if($dayt == '3'){?>
      <input type="checkbox" class="colour-button cbb2" name="v1" value="10 - 12" id="btn102<?php echo $counter;?>" /><label for="btn102<?php echo $counter;?>"> <i class="fa fa-check-circle hide14" id="chk-btn102<?php echo $counter;?>"></i>  <?php echo $times;?></label>
      <?php }?>  
      </center>
      </td>
      <td>
      <center>
      <?php if($dayt == '4'){?>
      <input type="checkbox" class="colour-button cbb3" name="v1" value="10 - 12" id="btn1032<?php echo $counter;?>" /><label for="btn1032<?php echo $counter;?>"> <i class="fa fa-check-circle hide15" id="chk-btn1032<?php echo $counter;?>"></i>  <?php echo $times;?></label>
      <?php }?>  
      </center>

      </td>
      <td>
     <center>
      <?php if($dayt == '5'){?>
      <input type="checkbox" class="colour-button cbb4" name="v1" value="10 - 12" id="btn1042<?php echo $counter;?>" /><label for="btn1042<?php echo $counter;?>"> <i class="fa fa-check-circle hide16" id="chk-btn1042<?php echo $counter;?>"></i>  <?php echo $times;?></label>
      <?php }?>  
      </center>
      </td>
    </tr>
    <?php }?>
  </table>
</form>

Open in new window


When I execute it in my database, I get more dates for different days than the my actual output. the $dayt='1' is monday, '2' is tuesday and so on until friday, how can I fix this? My output is in the image
see.png
The real output should be 4 dates on monday not just 1. 3 on wednesday and one on friday
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
Without seeing your data, we're just guessing.  A common approach might be to remove SELECT * and instead SELECT only the columns you want.  SELECT * is an anti-practice, and there is rarely any good reason to use it.  Another common approach is to expand the restrictions of the WHERE clause and add a LIMIT clause.

Author

Commented:
Ok so how do I make the wednesday and friday rows shift up? I dont want it to skip a row everytime
          <?php 
      while ($row3 = mysqli_fetch_assoc($result3))
      {
      	$counter++;
      	$dayt = $row3['day_of_week'];
      	//$times = $row3['time_window_label'];
      	//$tt= explode(",",$times);
      	//print_r($tt[1]);die;?>
    <tr>
      <td>
      <center>
<?php 
      
      if($dayt == '1'){ ?>
      	<input type="checkbox" class="colour-button cbb" name="v1" value="10 - 12" id="btn112<?php echo $counter;?>" /><label for="btn112<?php echo $counter;?>"> <i class="fa fa-check-circle hide12" id="chk-btn112<?php echo $counter;?>"></i>  <?php echo $row3['time_window_label'];?></label>

      <?php }?>
      </center>
      </td>
      <td>
      <center>
      <?php if($dayt == '2'){?>
      <input type="checkbox" class="colour-button cbb1" name="v1" value="10 - 12" id="btn1012<?php echo $counter;?>" /><label for="btn1012<?php echo $counter;?>"> <i class="fa fa-check-circle hide13" id="chk-btn1012<?php echo $counter;?>"></i>  <?php echo $row3['time_window_label'];?></label>
      <?php }?>  
      </center>
      </td>
      <td>
      <center>
      <?php if($dayt == '3'){?>
      <input type="checkbox" class="colour-button cbb2" name="v1" value="10 - 12" id="btn102<?php echo $counter;?>" /><label for="btn102<?php echo $counter;?>"> <i class="fa fa-check-circle hide14" id="chk-btn102<?php echo $counter;?>"></i>  <?php echo $row3['time_window_label'];?></label>
      <?php }?>  
      </center>
      </td>
      <td>
      <center>
      <?php if($dayt == '4'){?>
      <input type="checkbox" class="colour-button cbb3" name="v1" value="10 - 12" id="btn1032<?php echo $counter;?>" /><label for="btn1032<?php echo $counter;?>"> <i class="fa fa-check-circle hide15" id="chk-btn1032<?php echo $counter;?>"></i>  <?php echo $row3['time_window_label'];?></label>
      <?php }?>  
      </center>

      </td>
      <td>
     <center>
      <?php if($dayt == '5'){?>
      <input type="checkbox" class="colour-button cbb4" name="v1" value="10 - 12" id="btn1042<?php echo $counter;?>" /><label for="btn1042<?php echo $counter;?>"> <i class="fa fa-check-circle hide16" id="chk-btn1042<?php echo $counter;?>"></i>  <?php echo $row3['time_window_label'];?></label>
      <?php }?>  
      </center>
      </td>
    </tr>
    <?php }?>
  </table>
</form>

Open in new window


 

How can I solve this issue?see.png
Most Valuable Expert 2011
Top Expert 2016
Commented:
I think what you want may be a two-dimensional matrix.  But I don't have any test data to work with.  If I can find an example from my teaching library I'll come back and post it for you.

Author

Commented:
Can I solve this by making each of a different table but it looks like a whole table above? If so can you show me an example?

Author

Commented:
I took your advice and did a multi-dimension matrix, worked like a charm! Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial