Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.