php - 必须重视 else 在 php/(postgreSQL/MySQL) 中不打印任何内容
问题描述
这是我的代码。我必须在一列中打印整个州名。如果有任何值,它应该在该状态名称前面打印一些值,否则它应该在该状态前面打印 null 或零或空.. state 是一个表,asset_stage1 是另一个表。所有州名都应显示在选择日期上。还附上我当前的屏幕截图。如果状态代码存在状态并且资产stage1中存在相同的状态代码值,我必须与状态代码匹配它应该显示值否则它应该显示null
<div class="container">
<form action="<?php $_PHP_SELF ?>" method="POST">
<input type="date" name="timestamp" class="btn" placeholder="Enter date"/>
<input type="submit" name="search" class="btn" value="Search by date">
</form>
<table>
<tr>
<th>Date</th>
<th>State Name</th>
<th>Asset Download Stage1</th>
<th>Asset Download Stage2</th>
<br>
<?php
ini_set("display_errors","Off");
$pgcon = pg_connect("dbname=nrega host=localhost port=5432 user= postgres");
if(isset($_POST['search']))
{
$timestamp = $_POST['timestamp'];
//Stage 1
$query1 = " select count(*) as stage1, a.state_code,b.state_name,
timestamp::date from asset_stage1 a,states b where timestamp::date >= '$timestamp' and
a.state_code not in ('06') and a.state_code=b.state_code group by 2,3,4 order by b.state_name
";
//Stage 2
$query2 = "select count(*) as stage2, a.state_code,b.state_name, timestamp::date from asset_stage2 a,
states b where timestamp::date >= '$timestamp' and
a.state_code not in ('06') and a.state_code=b.state_code group by 2,3,4 order by b.state_name
";
// state_code
$query4 = "select distinct state_name, state_code from states order by state_name";
$result4 = pg_query($pgcon,$query4);
$m=0;
global $state_code;
while($row = pg_fetch_array($result4))
{
$state_name[$m]=$row ['state_name'];
$state_code[$m]= $row ['state_code'];
$m++;
}
$result = pg_query($pgcon,$query1);
$i=0;
while($row = pg_fetch_array($result))
{
if($state_code[$i] == $row['state_code'])
{
//echo $row['state_code'];
$stage1_count[$i]=$row ['stage1'];
}
else
{
$stage1_count[$i]=0;
}
$date_store[$i]=$row ['timestamp'];
$i++;
}
$result2 = pg_query($pgcon,$query2);
$j=0;
while($row = pg_fetch_array($result2))
{
if($state_code[$j] == $row['state_code']){
$stage2_count[$j]=$row ['stage2'];
}
else
{
$stage2_count[$j]= 0;
}
//$stage2_count[$j]=$row ['stage2'];
$j++;
}
$len= sizeof($state_name);
for($i=0;$i<=33;$i++)
{
?>
<tr>
<td><?php echo $timestamp;?></td>
<td><?php echo $state_name[$i];?></td>
<td><?php echo $stage1_count[$i];?></td>
<td><?php echo $stage2_count[$i];?></td>
</tr>
<?php
}
}
?>
</table></div>
解决方案
对于表asset_stage1
:
SELECT state_name, count(*) FROM states, asset_stage1 WHERE states.state_code=asset_stage1.state_code GROUP BY state_name;
对于表asset_stage2
:
SELECT state_name, count(*) FROM states, asset_stage2 WHERE states.state_code=asset_stage2.state_code GROUP BY state_name;
推荐阅读
- javascript - Google Auth 用户加密属性
- ios - 如何查找应用程序上应用了哪个 iOS 分发证书(内部、内部使用的应用程序)?
- javascript - 拖动图像时非常奇怪的行为
- python-3.x - 同时运行 2 个无限循环切换控制 - Python3
- javascript - extraReducers 没有持久化
- c# - 使用 SSH.NET 执行命令不会产生任何输出
- python - 当用户是角色 discord.py 时,头像命令给出错误
- python - 来自 Keras 的神经网络模型的准确性没有提高
- json - 如何对 JSON 数据数组进行分页?
- npm - 尽管将包移动到 `devDependencies`,`npm audit --production` 仍然警告漏洞