I can't get my table to display on smaller screen resolutions

Hello,

I am trying to show different elements based on the size of the screen resolution. I am using the following commands. <div class="d-none d-sm-block"> and  <div class="d-block d-sm-none">.

These commands are working as I hoped, and the elements (tables) which I want to be displayed based on the screen resolution are being displayed correctly. However, when I try to add dynamic data to the tables using php, the table (in the smaller screen resolution) does not display. I do not understand why.

This is my code:

<?php
					  
					  $day   = isset($_POST['day'  ]) ? $_POST['day'  ] : null;
					  $month = isset($_POST['month']) ? $_POST['month'] : null;
					  $year  = isset($_POST['year'])  ? $_POST['year'] : null;
					  
					  
					  //$whereClause = [];
					  
					// if ($day) {
						 //$whereClause[] = 'day = "'. mysqli_real_escape_string($db_connection, $day) .'"';
					// }
					 
					// if ($month) {
						// $whereClause[] = 'month = "'. mysqli_real_escape_string($db_connection, $month) .'"';
					 //}
					 
					// if ($year) {
						 //$whereClause[] = 'year = "'. mysqli_real_escape_string($db_connection, $year) .'"';
					// }
					 
					 
										 
					 $sql = "SELECT * FROM songs_table WHERE day = '".$day."' AND month = '".$month."' AND year >= '".$year."'";
					 $result = mysqli_query($db_connection, $sql);
					 
					 if (mysqli_num_rows($result) > 0) {
						 
					 ?>
					 


					<br><br><br><br><br>
				
					<div class="d-none d-sm-block">
						
						Show me on everything but smallest screen.
						
						<table class="table table-dark">
								  <thead>
									<tr>
									<th scope="col"><h4>act</h4></th>
									<th scope="col"><h4>title</h4></th>
									<th scope="col"><h4>year</h4></th>
									<th scope="col"><h4>Youtube</h4></th>
									<th scope="col"><h4>Amazon</h4></th>
									</tr>
								  </thead>
								 
								 <tbody>
									<?php while($song = mysqli_fetch_array($result)) 
											{ 															//WE ARE USING A WHILE LOOP TO POPULATE THE TABLE
									?> 				
											<tr>
											<td><?php echo $song['artist']; ?></td>
											<td><?php echo $song['title']; ?></td>
											<td><?php echo $song['year']; ?></td>
											<td><iframe width="220" height="145" src="<?php echo $song['youtube'];?>" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></td>
											<td><a href = "<?php echo $song['amazon']; ?>"target="_blank" >Amazon<a/></td>
											</tr>
											</tbody>
									  <?php } ?>	
								 
								 
						</table>
						
						
					</div>
					<div class="d-block d-sm-none">
						Show me on smallest screen only.
						
						<table class="table">
						  <thead>
							<tr>
							  <th scope="col"><h4>BirthdaySong</h4></th>
							</tr>
						  </thead>
						  
						  <tbody>
						  
						  <?php while($song = mysqli_fetch_array($result)) 
											{ 															//WE ARE USING A WHILE LOOP TO POPULATE THE TABLE
									?> 
						  
							<tr>
							 <td><?php echo $song['artist']; ?> <br> 1976 <br> Youtube <br> Amazon</td>
							</tr>
							
							<tr>
							 
							  <td>Mark, Dance with somebody <br> 1976 <br> Youtube <br> Amazon</td>
							</tr>
							
							<tr>
							  
							  <td>Mark, Dance with somebody <br> 1976 <br> Youtube <br> Amazon</td>
							</tr>
							
						
							
						  </tbody>
						  
						   <?php } ?>
						</table>
						
						
					</div>
				
					
					 
				 <?php } ?>

Open in new window


To confirm, the table displays correctly on the large, medium and small resolutions but in the xtra small resolution, the dynamic table is not displaying. I noticed when I remove the line:

 <?php while($song = mysqli_fetch_array($result)) 
											{ 															
									?> 

Open in new window


... the table and the static text displays. When the line is then re-added the table disappears and no text appears.

Any advice on why this is happening and how to resolve would be great. Many thanks.
AdamTrying to learn phpAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
When you call mysqli_fetch_array it moves the pointer on (so it can loop through the records). By the time you call it a second time on line 81, the pointer is already at the end of the set, so there are no more records to show, which is why your while loop doesn't run through a second time.

You need to reset the pointer before looping through the second time. Add this just before your second loop:

mysqli_data_seek($result, 0);
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AdamTrying to learn phpAuthor Commented:
Wonderful. Many thanks Chris Stanyon.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.