可以将HTML嵌入到PHP中“if if”声明? [英] Can HTML be embedded inside PHP "if" statement?

查看:234
本文介绍了可以将HTML嵌入到PHP中“if if”声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将HTML嵌入PHP if语句中,如果甚至可能的话,因为我认为HTML会在PHP if语句执行之前出现。

我试图访问数据库中的表。我在HTML中创建了一个下拉菜单,列出了数据库中的所有表格,一旦从下拉列表中选择了表格,我就点击了提交按钮。

我使用isset函数来查看提交按钮是否被按下,并在PHP中运行一个循环来显示数据库中表的内容。所以在这一点上我有完整的表,但我想在这张表上运行更多的查询。因此,我试图在if语句中执行更多的HTML。最终,我试图在表中更新(一行或多行中的一个或多个内容)或删除(一行或多行)内容。我想要做的是创建另一个下拉对应表中的列,以使表搜索更容易,单选按钮对应于我是否想更新或删除表中的内容。

解决方案

 <?php if($ condition):?> 
< a href =http://yahoo.com>只有$ condition为真时才会显示< / a>
<?php endif; ?>

根据要求,这里是elseif和else(你也可以在文档

 <?php if($ condition):?> 
< a href =http://yahoo.com>只有$ condition为真时才会显示< / a>
<?php elseif($ anotherCondition):?>
more html
<?php else:?>
甚至更多html
<?php endif; ?>

就是这么简单。



HTML只有在满足条件时才会显示。


I would like to embed HTML inside a PHP if statement, if it's even possible, because I'm thinking the HTML would appear before the PHP if statement is executed.

I'm trying to access a table in a database. I created a pulldown menu in HTML that lists all the tables in the database and once I select the table from the pulldown, I hit the submit button.

I use the isset function to see if the submit button has been pressed and run a loop in PHP to display the contents of the table in the database. So at this point I have the complete table but I want to run some more queries on this table. Hence the reason I'm trying to execute more HTML inside the if statement. Ultimately, I'm trying to either update (1 or more contents in a row or multiple rows) or delete (1 or more rows) contents in the table. What I'm trying to do is create another pulldown that corresponded to a column in a table to make the table search easier and radio buttons that correspond to whether I'd like to update or delete contents in the table.

解决方案

<?php if($condition) : ?>
    <a href="http://yahoo.com">This will only display if $condition is true</a>
<?php endif; ?>

By request, here's elseif and else (which you can also find in the docs)

<?php if($condition) : ?>
    <a href="http://yahoo.com">This will only display if $condition is true</a>
<?php elseif($anotherCondition) : ?>
    more html
<?php else : ?>
    even more html
<?php endif; ?>

It's that simple.

The HTML will only be displayed if the condition is satisfied.

这篇关于可以将HTML嵌入到PHP中“if if”声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆