[英]PHP MYSQL How to find if a variable exists in mysql_fetch_assoc and its position in the array then set result as variables
[英]how to pass a post variable in mysql_fetch_assoc result
if($_POST)
{
$client = $_POST['client'];
$insu1 = $_POST['insu1'];
$insu2 = $_POST['insu2'];
$date = date("dmY");
if($insu2 = 'alp' or $insu2='bppi' or $insu2='cpmp' or $insu2='carp' or $insu2='dsp' or $insu2='eep' or $insu2='earp' or $insu2='mbp')
{
//set @insu2 = $insu2;
$sql2 ="Select '$insu2' from tbl_engineering order by timestamp( `timestamp` ) DESC limit 1 ";
$result2=mysql_query($sql2);
//$insu2_name ='';
var_dump($result2);
while($row = mysql_fetch_assoc($result2))
{
echo $insu2;
var_dump($row);
$insu2_name = $row[$_POST['insu2']];
echo $insu2_name;
}
來自$insu2_name = $row[$_POST['insu2']]
; 我得到列名,但我想要列Value。 $insu2_name = alp(column name of database)
輸出$insu2_name = alp(column name of database)
伙計們幫助我
你知道嗎
select anyRandomSrting from table
如果anyRandomSrting不是表中的列,則將返回anyRandomSrting。
在你的情況下,$ _POST ['insu2']中不會有一個列名。
更新
檢查此查詢一次
"Select $insu2 from tbl_engineering order by timestamp( `timestamp` ) DESC limit 1"
請檢查我是否已從$ insu2中刪除了'
嘗試更改$insu2_name = $row[$_POST['insu2']];
to $insu2_name = $row['insu2'];
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.