How to retrieve all the php value at once and store in a table..?

Guys whats wrong in my code…Im trying to retrieve the value from database and store in html table…but only one value is inserted in the table and remaining values are not inserted …

Below is how my output looks like

Below is my php code

     <?php
  include 'db.php';
  ?>
 <html>
<head>
<title>Inverter info</title>
<link rel="stylesheet" href="css/five.css"> 
<link rel="stylesheet" href="css/table.css"/>
 <link rel="stylesheet" href="reference/bootstrap.min.css">

 <script src="reference/jquery.min.js"></script>

</head>
<body>
<form method="post">
 <div  class="wrapper">
 <div class="bg">
<div class="search-container">
  <div class="search-bg"></div>
<div class="search">

 <label for="dropdown">Inverter</label>
 <select name="options" id="dropdown" class="selectpicker">
  <option>Select The Inverter</option>
    <option value="1">Inverter 1</option>
   <option value="2">Inverter 2</option>
  <option value="3">Inverter 3</option>
   <option value="4">Inverter 4</option>
   <option value="5">Inverter 5</option> 
   <option value="6">Inverter 6</option>
 </select><br><br>
  <input type="submit" class="btn btn-default" name="submit" onclick="show()">
  <input type="reset"     class="btn btn-default" value="Reset  "><br/><br/>
  <input type="button"  data-toggle="modal" href="#myModal" class="btn btn-primary" name="Show Table" value="show Table" id="table">
</div></div></div></div>  
 <div id="myModal" class="modal fade in">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                
                <div class="table-title">
				<h3>Inverter Details</h3>
				</div>
				<table class="table-fill" id="tabid">
				<thead>
            </div>
		 
	<div class="modal-body">
		<tr>
		<th class="text-left">Inverter</th>
		<th class="text-left">TimeStamp</th>
		<th class="text-left">Grid power total(W)</th>
		</tr>
		</thead>
<?php 
 if(isset($_POST["options"],$_POST["submit"]))
{
  $inverter = $_POST["options"];
  $query = "select * from inverterlog where inverter = '" . $inverter . "'";
  $execute = mysqli_query($con,$query);
  if($execute !== FALSE && mysqli_num_rows($execute)> 0)
  {
    while($row = mysqli_fetch_array($execute))
	{
		
    ?>		

		<tbody class="table-hover">
		<tr>
		<td class="text-left"><?php echo $row['inverter']; ?></td>
		<td class="text-left"><?php echo $row['timestamp']; ?></td>
		<td class="text-left"><?php echo $row['gridpowertotal']; ?></td>
		</tr>
		</tbody>
		</table>
	</div>		 
 
	<div class="modal-footer">
                <div class="btn-group">
				    <button class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Cancel</button>
				</div>
				<div class="btn-group">
					<button id="change-chart"  class="btn btn-primary"><span class="glyphicon glyphicon-check"></span>Save</button>
				  </div>
      </div>
	  </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
 <?php
	}
  }
 else
  {
	   echo '<script language="javascript">';
		   echo 'alert("Data does not exist....")';
		   echo '</script>';
  }
 }	
 ?>	 
</form>
<script>

</body>
</html>

you create invalid HTML, hence only the valid modal (with the first data set) will show up.

@Dormilich…how to include all the values inside that single modal…?? please tell me where is the mistake in my php…??

your mistake is that your loop includes way too much HTML. you only need to loop over the table rows.

2 Likes

That would suggest there is only one row where the value of inverter equals the value you post.
But what you are doing with html in the while loop does not make much sense to me.
And this:-

  $inverter = $_POST["options"];
  $query = "select * from inverterlog where inverter = '" . $inverter . "'";
  $execute = mysqli_query($con,$query);

…is wide open to sql injection. :fearful:

2 Likes

@Dormilich@SamA74…thank u for ur suggesstion …I solved the issue…i havd misplaced the modal footer…ive placed it inside the while…therefore in eacj=h iteration it used create a new footer and hence was printing the value outside the modal…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.