Jump to content

Raido button advice


Stephen68

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/157811-raido-button-advice/
Share on other sites

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];
}

Link to comment
https://forums.phpfreaks.com/topic/157811-raido-button-advice/#findComment-832303
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.