jbradley04 Posted July 8, 2010 Share Posted July 8, 2010 I hope I can explain this but I am having a lot of difficulty with this. So what I am trying to do is pass a list of users that someone picks on the form.... <input type="checkbox" name="who[]" value="{$results[nr].user_id}" /> This is through Smarty Templates loop Next I am trying to process this info from PHP and pass it to smarty template..... $who = $_POST['who']; foreach($who as $x) { $list = $x; } But before I pass the variable $list I am looking to do a query to get usernames $query = mysql_query("SELECT username FROM users WHERE id = '$list'"); Then I will pass the variable $list and the respective username to tpl file... At this point I guess I will do a foreach loop on SMARTY too.... I am not sure... I hope I explained that ok.... Any help would be greatly appreciated! Thanks to all! J Quote Link to comment https://forums.phpfreaks.com/topic/207192-passing-an-array-from-a-form-and-using-it/ Share on other sites More sharing options...
trq Posted July 9, 2010 Share Posted July 9, 2010 Do you have any code? Quote Link to comment https://forums.phpfreaks.com/topic/207192-passing-an-array-from-a-form-and-using-it/#findComment-1083414 Share on other sites More sharing options...
jbradley04 Posted July 10, 2010 Author Share Posted July 10, 2010 Not really... What I put in the original post is all I have... I am trying to take this array from a form <input type="checkbox" name="who[]" value="{$results[nr].user_id}" /> and convert that into a variable so I can search Mysql $who = $_POST['who']; foreach($who as $x) { $list = $x; } $query = mysql_query("SELECT username FROM users WHERE id = '$list'"); Just not working... I am sure I am way off but I think I need a for each command.... Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/207192-passing-an-array-from-a-form-and-using-it/#findComment-1084040 Share on other sites More sharing options...
kenrbnsn Posted July 10, 2010 Share Posted July 10, 2010 Think about it, when you do <?php $who = $_POST['who']; foreach($who as $x) { $list = $x; } ?> you're converting an array to one variable, which is not what you want to do. You probably want something like this: <?php $q = "SELECT username FROM users WHERE id in ('" . implode("','", $_POST['who']) . "')"; $query = mysql_query(q) or die("Problem with the query: $q<br>" . mysql_error()); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/207192-passing-an-array-from-a-form-and-using-it/#findComment-1084050 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.