We help IT Professionals succeed at work.

Unwanted output from my query

Jazzy 1012
Jazzy 1012 asked
on
172 Views
Last Modified: 2017-03-28
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

Most Valuable Expert 2011
Author of the Year 2014

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
Author of the Year 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

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!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions