Link to home
Start Free TrialLog in
Avatar of Jazzy 1012
Jazzy 1012

asked on

Unwanted output from my query

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
User generated image
The real output should be 4 dates on monday not just 1. 3 on wednesday and one on friday
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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.
Avatar of Jazzy 1012
Jazzy 1012

ASKER

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?User generated image
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
I took your advice and did a multi-dimension matrix, worked like a charm! Thanks!