gpt4 book ai didi

php - 如果出现$ Error,PHP将不显示网格

转载 作者:行者123 更新时间:2023-12-03 08:25:15 24 4
gpt4 key购买 nike

我具有以下应有的语法,并且在按钮按下事件上将首先验证是否已将开始日期和结束日期输入到文本框中,如果其中一个为空白,则会在屏幕上显示一条消息,通知用户它是空的。

我的语法存在的问题是,即使错误消息显示在屏幕上,语法也会继续迭代,并且表的标题行仍会显示(并且我假设如果查询将返回数据,那么表也将填充数据) 。应该如何更改此语法,以便如果错误显示在屏幕上,则一旦错误显示在屏幕上,代码就会停止?

<?php  
if(isset($_POST['submit'])){

$begindateerror = false;
$enddateerror = false;
if (empty($_POST['begindate'])) {
$begindateerror = true;
}
if (empty($_POST['enddate'])) {
$enddateerror = true;
}

if ($begindateerror) {
echo "<strong>Please select a begin date.</strong><br>";
} else { }
if ($enddateerror) {
echo "<strong>Please select a end date.</strong><br>";
} else { }

$option = array();

//Build option array for connection string

$db = JDatabase::getInstance( $option );
$tsql = $db->gettsql(true);
$tsql = "SQL tsql";

$db->settsql($tsql);
$tsql = $db->loadObjectList();

$numofrows = mssql_num_rows($tsql);

?>
<table border="1">
<thead>
<tr>
//Create Header Row for the table
</tr>
</thead>
<tbody>
<?php
foreach( $tsql as $result ) {
print "<tr>";
//write the query results to the table
print "</tr>";
}}?>

最佳答案

您可以将所有后面的代码放在else括号内的错误之后,然后让PHP回显标题:

<?php
if(isset($_POST['submit'])){
$begindateerror = false;
$enddateerror = false;
if (empty($_POST['begindate'])) {
$begindateerror = true;
}
if (empty($_POST['enddate'])) {
$enddateerror = true;
}
if ($begindateerror) {
echo "<strong>Please select a begin date.</strong><br>";
} else if ($enddateerror) {
echo "<strong>Please select a end date.</strong><br>";
} else {
$option = array();
//Build option array for connection string
$db = JDatabase::getInstance( $option );
$tsql = $db->gettsql(true);
$tsql = "SQL tsql";
$db->settsql($tsql);
$tsql = $db->loadObjectList();
$numofrows = mssql_num_rows($tsql);
echo '<table border="1"><thead><tr></tr></thead><tbody>';
foreach( $tsql as $result ) {
print "<tr>";
//write the query results to the table
print "</tr>";
}
}
}
?>

关于php - 如果出现$ Error,PHP将不显示网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43956634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com