[請益] 用POST傳遞的array的值永遠是最後一項..
用for把SQL裡的資料列出來並在後面加上一個按鈕傳遞值
code如下(只列出重點)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Snapshot List</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
$link = mysql_connect("127.0.0.1", "root", "1234") or die("Could not
connect : " . mysql_error());
mysql_select_db("FT_info") or die("Could not select database");
$query="Select * from list";
$result = mysql_query($query) or die("Query failed : " .
mysql_error());
$alumni_id=$line['serialno'];
mysql_close($link);
?>
<form action="http://127.0.0.1/site/tag.php"
method="POST">
<?php
for ($i=0;$line = mysql_fetch_assoc($result);$i++)
{
$tag[$i] = $line["Tag"];
echo "<td>".'<input type="hidden" name="Tag" value='.$tag[$i].'><input
type="submit" value='."$tag[$i]".'>'."</td>\n";
}
?>
while版
<?php
while ($line = mysql_fetch_assoc($result))
{
echo "<td>".'<input type="hidden" name="Tag" value='. $line["Tag"];.'><input
type="submit" value='. $line["Tag"].'>'."</td>\n";
}
?>
</form>
</body>
</html>
tag.php code如下
<?php
echo "debug msg: ";
echo $_POST["Tag"];
?>
按鈕顯示的值是正常的
但不管按哪個button送出去的值一直都是array的最後一個值
請求各位幫忙
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.162.191.133
→
08/21 14:47, , 1F
08/21 14:47, 1F
→
08/21 14:47, , 2F
08/21 14:47, 2F
→
08/21 14:48, , 3F
08/21 14:48, 3F
→
08/21 14:57, , 4F
08/21 14:57, 4F
→
08/21 14:59, , 5F
08/21 14:59, 5F
推
08/21 15:00, , 6F
08/21 15:00, 6F
→
08/21 15:00, , 7F
08/21 15:00, 7F
※ 編輯: BoxsterX 來自: 1.162.191.133 (08/21 15:09)
→
08/21 15:10, , 8F
08/21 15:10, 8F
→
08/21 15:26, , 9F
08/21 15:26, 9F
→
08/21 15:26, , 10F
08/21 15:26, 10F
→
08/21 15:30, , 11F
08/21 15:30, 11F
→
08/21 15:42, , 12F
08/21 15:42, 12F
→
08/21 15:42, , 13F
08/21 15:42, 13F
→
08/21 16:53, , 14F
08/21 16:53, 14F
→
08/21 16:59, , 15F
08/21 16:59, 15F
→
08/21 17:00, , 16F
08/21 17:00, 16F
name後面有括號 用 print_R($_POST) 接收會變成print出所有我在DB裡的東西
name後面沒括號
用'<input type="hidden" name="re_snapshotTag"value='.$line["snapshotTag"].'>
接收:echo $_POST["re_snapshotTag"]; 在單一input是可以正確的print出我在
button上的值
但用了多個input會回到我最一開的問題他只會print出array最後的值
所以我想請問能不能用一個button送出多個值並print出正確的值
code:
echo "<td>".'<input type="hidden" name="re_snapshotTag[]"
value='.$line["snapshotTag"].'>
<input type="hidden" name="count[]" value='.$i.'>
<input type="hidden" name="re_imagePath[]" value='.$line["imagePath"].'>
<input type="submit" value="Restore"> '."</td>\n";
※ 編輯: BoxsterX 來自: 36.228.19.164 (08/21 18:08)
討論串 (同標題文章)
PHP 近期熱門文章
PTT數位生活區 即時熱門文章