dragon8837 2018-07-20 14:47
浏览 100

在html中根据DIV ID设置php变量

I'm trying to find a way to get Div ID values from an included file's html and use them for comparison in a php if statement. I have a page called templates.php which uses a href value to grab a certain template, in this case fullwidth.php Initially, this gets the value from the URL and if it's 1 it loads the full page template, else it loads the half page template. That functionality works fine:

<!-- Get value from href -->
<?php $value = isset($_GET['value']) ? $_GET['value'] : 1;
      if($value == 1){ 
      include 'class/fullWidth.php';
      }else{
        include 'class/halfWidth.php';
      }
?>

Once $value dictates what template to load, I'm trying to set a value $panelType off of the panel Div so I know which panel type to save to my database. For example, on my fullwidth.php page I have one full width panel:

<div class="col-lg-12 fullWidth" id="full">
    <div class="fullContent" style="background-color: white; height: 100%;">

    </div>
</div>

so back on templates.php, I would take the #full as the div ID and use this to set my variable $panelType.

Which is where I add this and try:

<?php $value = isset($_GET['value']) ? $_GET['value'] : 1;
    $panel = $html->find('div[id]'); //including this to pull in DIV IDs
      if($value == 1){ 
          include 'class/fullWidth.php';
              if($panel == 'full'){
                $panelType = 1;
              }// including this block to say if the Div ID is 'full', set $panelType = 1
      }else{
        include 'class/halfWidth.php';
      }
?>

But this breaks the pages and it looks like a general php or formatting error. I'm not sure what exactly I'm doing wrong here, maybe there's a better way to use the div ID I want for the php variable. Eventually I will expand this so I just want to know how I can modify this to just say "If the Div ID is this, set the $panelType to this, etc."

  • 写回答

1条回答 默认 最新

  • douwen3083 2018-07-20 14:52
    关注

    you can just set the $panel inside your fullwidth template like:

    $panel = "full";
    <div class="col-lg-12 fullWidth" id="full">
        <div class="fullContent" style="background-color: white; height: 100%;">
    
        </div>
    </div>
    

    and then when you load it, the second code you wrote will work ;)

    but that only works, if you can set the panel manually? if there can also be other "panel id's" then this will not work and I think you have more then one id's?

    if the id will always be full, i dont see why you need to check that?

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c