0

我正在从 mysql 数据库中提取地址。地址通过数组以表格形式显示,作为一个列表,每个地址都有一个(隐藏的)输入和一个(提交)输入。意图是用户可以通过他们想要查看的地址单击(提交)输入,并且(隐藏的)输入将传递 ID(as_id)。

我编码的内容在一定程度上起作用。它显示地址和每个地址的输入。

不起作用的是,一旦为所选地址单击(提交),无论选择哪个(提交)输入,它都会传递“”。

我读过关于将输入转换为“名称”后带有“[]”的数组。我玩了一段时间。我得到了一个“strip_tags() 期望参数 1 是字符串,数组”错误,并且在这上面迷路了几个小时。我放弃了;没想到我正朝着正确的方向前进。

`enter code here`
echo "<div class='searchres'>";

echo "<form name='choose' method='post' id='choose' action='asset_search.php'>";

echo "<table>";

while ($asset_info = mysql_fetch_array($search_rs)) {

array_pop($asset_info);

        echo "<tr>";

          echo "<td width='400px'>";

          echo $asset_info['as_id'] . " ";

          echo $asset_info['as_st_number'] . " ";   

          echo $asset_info['as_st_dir'] . " ";

                echo $asset_info['as_st_name'] . " ";

          echo $asset_info['as_st_desig'] . " ";

          echo $asset_info['as_unit_num'] . " ";

          echo $asset_info['as_city'] . " ";

          echo "<br />";

          echo "</td>";

          echo "<td>";

          echo "<input name='hide' type='hidden' value='" . htmlspecialchars($asset_info
                ['as_id']) . "'>";

          echo "<input name='search' type='submit' id='search' value='View Property'>";

}

                echo "</td>";

        echo "</tr>";

echo "</table>";

echo "</form>";

echo "</div>";

我只需要传递 as_id,而不是整个数组。任何帮助,将不胜感激。

4

1 回答 1

0

I am assuming you want to check this line:

echo "<input name='hide' type='hidden' value='" . htmlspecialchars($asset_info['as_id']) . "'>";

You use the name hide, this should be hide[] then you should check for the value of $_POST['hide'].

Edited: But there is something else wrong with your code. You use one form for all addresses, with the same button for all addresses. You need to make a different form tag for each address. In that case you do not need to put [] behind the input name, although I would pick another name than 'hide'. Put the whole form in the while loop.

于 2013-04-29T15:42:27.783 回答