代码:
<?php
if($affiliated == '')
{
echo $affiliated;
}
else
{
$sql = "select * from all_university where university_id = '$affiliated'";
$result = mysqli_query($link,$sql);
while ($row = mysqli_fetch_array($result))
{
$short_name = $row['short_name'];
}
}
&GT;
在我的数据库表中,其字段名称是附属的,并且在不同的行中具有两个不同的值,其中一行具有&#39;整数&#39;价值和另一个有&#39;文本&#39;值。我想显示不同的值,即如果$ affiliated具有整数值,则打印整数其他打印文本。那么,我该如何解决这个问题呢?
谢谢
答案 0 :(得分:0)
首先,您需要检查$affiliated
是否numeric
并在每行检查我的评论
//check for integer
if (is_numeric($affiliated)) {
//condition for integer
// any number multiply by 1 equal to that number
$where = " WHERE concat('',university_id * 1) = university_id";
} else {
//condition for text
$where = " WHERE concat('',university_id * 1) != university_id";// here use not equal to condition
}
$sql = "select * from all_university" . $where;// pass $where accouding to avove condition
$result = mysqli_query($link, $sql);
while ($row = mysqli_fetch_array($result)) {
$short_name = $row['short_name'];
}