首页 > 解决方案 > 更改屏幕宽度时更改变量(例如横向到纵向)

问题描述

我正在将数据库中的消息显示到列中。在 iPhone(屏幕尺寸 375 X 812 像素)上查看时,它可以工作。然而,当手机变成横向(812 x375)时,列的数量不会改变这里是代码:

<div class="content">
  <table   class="table1"   width="98%">
<?php   $count = '0'; 
      if ($screenwidth < 481){$max_columns =3;}else {                                     
               $max_columns = 4;}
             do { 
                 if ($count < $max_columns){
                 if ($count == 0){
                     echo "<tr>"; 
                               }?>
 
      <td align="center"  class="td1">
                        <div>    <php echo $message ?>
        </div>
      </td>
          
   <?php } else { 
           $count = 0;
           echo "</tr><tr>";?>
          <td  align="center" class="td1">
         <div ><?php echo $message;</div>
       
       <?php echo "</td>";?>                           
              <?php } $count++; } 
       while($row_RS_Search = $RS_Search2->fetch() );
           echo "</tr>"; ?>
     </table></div>

然后我试图检索屏幕宽度,如下所示:

<?php
  $clientProps=array('screen.width','screen.height','window.innerWidth','window.innerHeight', 
    'window.outerWidth',);

  if(! isset($_POST['screenheight'])){

    echo "Loading...<form method='POST' id='data' style='display:none'>";
    foreach($clientProps as $p) {  //create hidden form
      echo "<input type='text' id='".str_replace('.','',$p)."' name='".str_replace('.','',$p)."'>";
    }
    echo "<input type='submit'></form>";

    echo "<script>";
    foreach($clientProps as $p) {  //populate hidden form with screen/window info
      echo "document.getElementById('" . str_replace('.','',$p) . "').value = $p;";
    }
    echo "document.forms.namedItem('data').submit();"; //submit form
    echo "</script>";

  }else{

    foreach($clientProps as $p) {   //create output table
     
    }
      $screenwidth =  $_POST['screenwidth'] ;
      $screenheight =$_POST['screenheight'];
   }
?>

这适用于加载页面,但是当屏幕转动时,屏幕不会改变。我知道这可能是 php 脚本,但是我对 AJAX 或 Java 不是很好,任何帮助将不胜感激

标签: javascriptphpajax

解决方案


推荐阅读