是否可以在php
和mysql
中使用查询从表中获取值并将值存储在变量中并在另一个查询的where条件中使用该变量,例如
$us = mysql_query("select regional from td_user where user_id='".$_SESSION['use_i']."'");
$us_row=mysql_fetch_row($us);
$reg = $us_row[`regional`] ;
现在我已将值存储在名为$reg
$sql = "SELECT * FROM td_excel where regional = '$reg'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result)
{
<?php echo $row['Vehicle_description'];?>
<?php echo $row['Year'];?>
//it will display many rows like this
}
它没有显示任何记录!!!!,我正在以正确的方式做到这一点..请帮助我!!! P.S我是学习者!!
答案 0 :(得分:0)
你试过这个吗?
$sql = "SELECT * FROM td_excel where regional = ".$reg;
答案 1 :(得分:0)
更改$us_row=mysql_fetch_row($us);
到$us_row=mysql_fetch_array($us);
并将$reg = $us_row[
地区] ;
更改为$reg = $us_row['regional'] ;