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++;
开发者_JS百科
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
Use arrays for the input names. Something like
<input type="radio" name="game' . $gamesLike['ID'] . '[haveOrWant]" value="have" />Have it
精彩评论