如何使用 php 处理每个搜索结果 2 个单选按钮
当我的用户在我的数据库中搜索游戏时,我向他们展示与他们的搜索词匹配的游戏列表,然后我想向每个项目添加一个按钮,允许用户选择“拥有它”或“想要它” ”然后有一个“添加”按钮,将他们的选择添加到他们的个人资料中。
因为你不能同时拥有它和想要它,我认为单选按钮将是最好的选择。
但现在我不知道如何处理按钮。当我点击搜索中的一个选项时,当我选择拥有或想要另一款游戏时,它将取消选择。
我知道我应该为每个搜索结果创建一个单独的名称表单,但是当将数据发送到我的控制器时我将如何管理数据?也许我需要增加表单名称,然后计算有多少结果并在我的控制器中使用它?
另外,我需要与选择关联的游戏ID,所以我需要为每个选择发送一个包含该数据的隐藏值,
也许我会以错误的方式处理这个问题...
这是我的代码,
echo '<div id="UserSearchGameResults">';
echo '<form action="#" method="Post">';
$x = 0;
while($gamesLike != null)
{
$x++;
echo '<div id="game_search_list_item">'.$x.'. '.$gamesLike['title'].'</div>
<span class="gamelistblue">
<input type="radio" name="haveOrWant" value="have" />Have it
</span>
<span class="gamelistorange">
<input type="radio" name="haveOrWant" value="want" />Want it
</span>
<input type="hidden" name="gameID" value="'.$gamesLike['ID'].'" />';
$gamesLike = $statement->fetch();
}
$statement->closeCursor();
echo '<br /> <input type="submit" value="Add Game(s)" />';
echo '</div></form>';
任何帮助都将受到关于如何处理该主题的
新想法的帮助也欢迎满足我的需求。
担
When my user searches for game in my DB, I present them with a list of the games that match their search term, and then i want to add a button to each item that allows the user to select "have it" or "want it" then have a single "add" button that adds their selections to their profile.
because you cant have it and want it at the same time, i assumed a radio button would be the best choice.
but now i am lost as to how to handle the buttons. When i click on one selection from the search, it will deselect when i choose have or want on another game.
I understand that i should be creating a separately name form for each search result, but then how would i manage the data when sending it to my controller? Maybe i need incrementing form names and then count how many results and use that in my controller?
Also, i need the gameID associated with the selections so i need to send a hidden value with that data for each selection
maybe i am going about this the wrong way...
heres my code
echo '<div id="UserSearchGameResults">';
echo '<form action="#" method="Post">';
$x = 0;
while($gamesLike != null)
{
$x++;
echo '<div id="game_search_list_item">'.$x.'. '.$gamesLike['title'].'</div>
<span class="gamelistblue">
<input type="radio" name="haveOrWant" value="have" />Have it
</span>
<span class="gamelistorange">
<input type="radio" name="haveOrWant" value="want" />Want it
</span>
<input type="hidden" name="gameID" value="'.$gamesLike['ID'].'" />';
$gamesLike = $statement->fetch();
}
$statement->closeCursor();
echo '<br /> <input type="submit" value="Add Game(s)" />';
echo '</div></form>';
any help is appreciated with the subject
new ideas on how to handle my needs are welcome too.
Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用数组作为输入名称。像这样的东西
Use arrays for the input names. Something like