PHP 板


LINE

看板 PHP  RSS
用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
1F:→ kerash:$line = mysql_fetch_assoc($result) ???? 08/21 14:47
2F:→ kerash:你是要用 mysql_num_rows 吗? 08/21 14:47
3F:→ BoxsterX:是的 08/21 14:48
4F:→ kerash:何不用 while($line=mysql_fetch_assoc()) ? 08/21 14:57
5F:→ BoxsterX:有试过用while但结果一样 08/21 14:59
6F:推 kerash:你改成while後再贴一次程式码,程式段落都要贴 08/21 15:00
7F:→ kerash:另外用原始码看你产生出来的 input 值是否正确 08/21 15:00
※ 编辑: BoxsterX 来自: 1.162.191.133 (08/21 15:09)
8F:→ BoxsterX:刚试过while了结果还是一样 08/21 15:10
9F:→ kerash:我看出来了 ... 你的NAME怎麽都一样... 08/21 15:26
10F:→ kerash:要买成name=Tag[] 才会把所有结果一次以阵列方式送出.. 08/21 15:26
11F:→ BoxsterX:感谢@@ 但我只要传出按钮的那一栏值 08/21 15:30
12F:→ kerash:那你应该不需要 hidden 啊,你直接把 submit 给 name 就好 08/21 15:42
13F:→ kerash:传过去就会是按下去的那个 name 的 value 08/21 15:42
14F:→ BoxsterX:目前都OK了 另外问一下 要怎麽做才能一个button传多个值 08/21 16:53
15F:→ kerash:如你这样做就行了,但是送出的 submit只要一个,其他都是 08/21 16:59
16F:→ kerash:放在 input 里面,再传过去另一页接收 08/21 17:00
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)







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BuyTogether站内搜寻

TOP