我想将SQL结果保存在变量中。
<?php
$sqlhost='localhost';
$username='user';
$passwort='passwd';
$database='...';
mysql_connect ($sqlhost,$username,$passwort);
mysql_select_db ($database);
$query= "SELECT * FROM Test";
$result = mysql_query($query) or die( mysql_error() );
while($row = mysql_fetch_array($result)){
echo $row['FB'];
}
$varibale = $row['ROW'];
echo $varibale;
?>
我想将其保存在变量中以使用WHERE ROW2 = '$varibale'
答案 0 :(得分:1)
在这部分代码中:
while($row = mysql_fetch_array($result)) {
echo $row['FB'];
}
$varibale = $row['ROW'];
echo $varibale;
您只能在$row
内访问while loop
,因此最简单的解决方案是创建阵列,填充阵列,然后访问。像这样:
$rowArray = [];
while($row = mysql_fetch_array($result)){
array_push($rowArray, $row['FB']);
}
$varibale = $rowArray['ROW'];
echo $varibale;