如何根据两个日期和时间之间的列显示表中的值


how can i display values from table according to a column between two dates and time?

>我有两个表浮动表(日期和时间,mitm,tagindex,value,status,marker)和tagtable(tagname,tagindex,tagtype,tagdatatype).我想将输出显示为

<form  method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
<p>REPORT</p>
Select AI Type:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="AI-Types" id="AI-Tpes">
<option value="select">--Select--</option>
<option value="DTP4">DTP4</option><option value="FT1">FT1</option><option value="FT2">FT2</option><option value="FT3">FT3</option><option value="LT1">LT1</option><option value="LT2">LT2</option><option value="PT1">PT1</option><option value="PT2">PT2</option>
<option value="PT3">PT3</option><option value="TE1">TE1</option><option value="TE2">TE2</option><option value="TE4">TE4</option><option value="VFD">VFD</option><option value="XT3">XT3</option><option value="XT4">XT4</option><option value="PT2">PT2</option>
</select><br><br>
<b>From Date:</b>
<input type="date" id="fromdate" name="fromdate" value="<?php if(isset($fromdate)) echo $fromdate;?>" size="20" />
<b>To Date:</b>
<input type="date" id="todate"   name="todate"   value="<?php if(isset($todate)) echo $todate;?>"     size="20"/><br><br>
<b>From Time:</b>
<input type="time" id="fromtime" name="fromtime" value="<?php  if(isset($fromtime))echo $fromtime;?>" size="30" />
<b>To Time:</b>
<input type="time" id="totime"   name="totime"   value="<?php if(isset($totime)) echo $totime;?>"     size="30"/><br><br>
<input type="submit" id="submit" name="submit"   value="GENERATE"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" id="reset" name="reset" value="RESET"/><br><br>
</div>
</body>
</html>
<?php
	 
	if(isset($_POST["submit"]))
	{
    $fromdate=$_POST['fromdate'];
	$todate=$_POST['todate'];
	$fromtime=$_POST['fromtime'];
	$totime=$_POST['totime'];	
	if(!$fromdate || !$todate ||!$fromtime||!$totime)
	echo " please provide all the fields";	
           global $conn; 	  
           // Create connection
              $conn = mysqli_connect('localhost', 'root', '','test');
           // Check connection
               if (!$conn) 
	            {
                 die("Connection failed: " . mysqli_connect_error());
                }
                $sql ="SELECT * FROM floattable WHERE TagIndex=$tagindex AND (DateAndTime between '$fromdate .'  '. $fromtime' AND '$todate .'  '. $totime') ORDER BY DateAndTime ASC;";
                $result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
	       function fill_data($tagindex)
		          
	        try{
				 function fill_data($tagindex)
				 {//for IP
					if  (($tagindex=0)||($tagindex=1)||($tagindex=2)||($tagindex=3)||($tagindex=4)||($tagindex=5)||($tagindex=6)||($tagindex=7)||($tagindex=8)||($tagindex=10)||($tagindex=11)||($tagindex=12)||($tagindex=13)||($tagindex=14)||($tagindex=14)||($tagindex=15)||
						($tagindex=16)||($tagindex=17)||($tagindex=18)||($tagindex=19)||($tagindex=20)||($tagindex=21)||($tagindex=22)||($tagindex=23)||($tagindex=24)||($tagindex=25)||($tagindex=26)||($tagindex=27)||($tagindex=28)||($tagindex=29)||($tagindex=30)||($tagindex=31)||($tagindex=32)||
						($tagindex=33)||($tagindex=34)||($tagindex=35)||($tagindex=36)||($tagindex=37)||($tagindex=38)||($tagindex=39)||($tagindex=40)||($tagindex=41)||($tagindex=42)||($tagindex=43)||($tagindex=44)||($tagindex=45)||($tagindex=46)||($tagindex=47)||($tagindex=48)||($tagindex=49))
						{
						// to display output
						echo "<table border='1' cellspacing='3' align='centre'>
						  <tr>
						  <th>DateAndTime</th>
						  <th>Millitm</th>
						  <th>TagIndex</th>
						  <th>Value</th>
						  <th>Status</th>
						  <th>Market</th>
						  </tr>";
							  while ($row = mysqli_fetch_array($result)) 
							{
							 echo " <tr>
							 <td>".$row['DateAndTime']."</td>
							 <td>".$row['Millitm']."</td>
							  <td>".$row['TagIndex']."</td>
							   <td>".$row['Val']."</td>
								<td>".$row['Status']."</td>
								 <td>".$row['Marker']."</td>
							 </tr>";
							}
							          echo "</table>";
				      	}
		        		  
			      }
			}
				 catch (Exception $e)
				 {
					 echo $e->getmessage();
					 exit(1);
				 }
				 
				    if(isset($_POST['submit']))
					{	
				      $selected_val = $_POST['AI-Types'];
				 try{
					 
					  $currentSheet = "DTP4";
                        fill_data(0);
                        fill_data(1);
                        fill_data(2);
                      
					    $currentSheet = "FT1";
                        fill_data(3);
                       
					    $currentSheet = "FT2";
                        fill_data(4);
						
						$currentSheet = "FT3";
                        fill_data(5);
						fill_data(6);
                        $currentSheet = "LT1";
                        fill_data(7);
                       
					   $currentSheet = "LT2";
                        fill_data(8);
						fill_data(9);
						
						$currentSheet = "PT1";
                        fill_data(10);
						$currentSheet = "PT2";
                        fill_data(11);
						fill_data(12);
						fill_data(13);
						fill_data(14);
						
						$currentSheet = "PT3";
                        fill_data(15);
						fill_data(16);
						
						$currentSheet = "TE1";
                        fill_data(17);
						fill_data(18);
						fill_data(19);
						
						$currentSheet = "TE2";
                        fill_data(20);
						fill_data(21);
						fill_data(22);
						fill_data(23);
						
						$currentSheet = "TE4";
                        fill_data(24);
						fill_data(25);
						fill_data(26);
						fill_data(27);
						fill_data(28);
						fill_data(29);
						
                        $currentSheet = "VFD";
                        fill_data(30);
						fill_data(31);
						fill_data(32);
						fill_data(33);
						fill_data(34);
						fill_data(35);
						fill_data(36);
						
						$currentSheet = "XT3";
                        fill_data(37);
						fill_data(38);
						$currentSheet = "XT4";
                        fill_data(39);
						$currentSheet = "PT2";
                        fill_data(40);
						
				   
				   }
				        catch (Exception $e)
					      {
						  echo $e->getmessage();
					      exit(1);
						  }
                    }
			mysqli_close($conn);
			
			
		}			
 
	
?>

但问题是在浮动标签索引中位于 0-81 个索引中,我想获取所有具有其标签索引的记录,例如。 1 但条件是我必须根据标签表中的标签名称对数据进行排序,例如。DTP4_xxxx/IP(它是一个标签名称)。我写了一个方法fill_data($tagindex)。我是PHP.plz的新手,帮助我。提前致谢

试试这个。

$date="2012-12-25";
  $time="00:00:00";
  $date1="2012-12-25";
  $time1="23:59:59";
  $firstdatetime=$date." ".$time;
  $seconddatetime=$date1." ".$time1;
  $data=mysql_query("SELECT * FROM floattable 
WHERE DateAndTime BETWEEN '$firstdatetime AND '$seconddatetime'");