2 回答
TA贡献1815条经验 获得超6个赞
假设您想要一行中的结果,请执行两次SELECT并从每个中选择结果:
SELECT height, age FROM (
( SELECT `field_2` AS height FROM tbl WHERE `id`=1 AND `field_1`='height') t1,
( SELECT `field_2` AS age FROM tbl WHERE `id`=1 AND `field_1`='age') t2
)
或者,如果您不介意解析结果:
SELECT * FROM `tbl` WHERE id=3 AND ( field_1='height' OR field_2='age' )
然后您的 PHP 代码将必须检查每一行的heightor age:
if ( $row['field_1'] == 'age' ) {
// $row['field_2'] is the age
} else if ( $row['field_2' == 'height' ) {
// $row['field_2'] is the height
}
TA贡献1859条经验 获得超6个赞
尝试这个
$arr = [];
$height;
$width;
$q = "SELECT `field_2` FROM
`table_Nam` WHERE `id` = 3";
$result =
mysqli_fetch_assoc(mysqli_query
($con, $q));
while($row = $result){
if($row['field_1'] ==
'height')
{
$height = $row['field_2'];
}else if($row[field_2'] ==
'age'){
$age = $row['field_2'];
}
}
希望这可以帮助
- 2 回答
- 0 关注
- 99 浏览
添加回答
举报