Stephen68 Posted May 12, 2009 Share Posted May 12, 2009 Ok I have a form that is submitted that has some radio buttons that are created on the fly. I gave them all the same name, this should put them all into an array right? e.g. <input type='radio' name='cert[]' value='id'> and <input type='radio' name='recert[]' value='id'> Ok this is the part that I would like advice with. Each value of the input is an id of a entree in the database. I am making a message to email and let me know what was filled out. My first though was that I should loop through the id's and then somehow put them into my SQL statment. I could not find a way to do this other then using a whole bunch of AND's. If anybody knows a easy way of making the statement please let me know. e.g. SELECT * FROM table WHERE id='1' AND id='2' AND id='10' My next thought was to grab everything in the database and then using in_array while looping through the table rows. e.g. This code is not tested in anyway just wanted to get my idea out <?php //Get the id from cert radio buttons $cert = $_POST['cert']; $num = count($cert); for ($i=0; $i >= $num; $i++) { $id[] = $cert[$i]; } //Loop through table rows and if in array add to message $result = mysql_query("SELECT * from table) or die ('wow that didn't work'); while ($row = mysql_fetch_array($result)) { if (in_array($row['id'],$id) { //The id match add to message $message .= $row['somevalue']; } } ?> Ok is there a better way of doing this or is the in_array() one good enough? Thanks for your time guys Stephen Quote Link to comment https://forums.phpfreaks.com/topic/157811-raido-button-advice/ Share on other sites More sharing options...
Adam Posted May 12, 2009 Share Posted May 12, 2009 I can't see any reason why it wouldn't work, but you're going a round-about way of doing it. You could just put $cert straight into the in_array() function, removing the need for: $num = count($cert); for ($i=0; $i >= $num; $i++) { $id[] = $cert[$i]; } Quote Link to comment https://forums.phpfreaks.com/topic/157811-raido-button-advice/#findComment-832303 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.