is this the proper way to add multiple text fields at once into mysql?

this works perfect but is this the proper way to do this?

<?
/////////////////add/////////////////////////////////

    for ($i=0; $i<count($_POST['newhour_start']); $i++) {   
        if ($_POST['newhour_start'][$i] !="" && $_POST['newhour_end'][$i] !="" ) {
            $inserthour = mysql_query("INSERT INTO hour 
            (hour_start,hour_end,hour_day) VALUES 
            ('".$_POST['newhour_start'][$i]."','".$_POST['newhour_end'][$i]."','".$_POST['newhour_day'][$i]."')");
        }
    }
?>
Start:<input name="newhour_start[]" type="text" id="newhour_start" > End: <input name="newhour_end[]" type="text" id="newhour_end" ><input name="newhour_day[]" type="hidden" id="newhour_day" value="Monday" >

Start:<input name="newhour_start[]" type="text" id="newhour_start" > End: <input name="newhour_end[]" type="text" id="newhour_end" ><input name="newhour_day[]" type="hidden" id="newhour_day" value="Monday" >

Start:<input name="newhour_start[]" type="text" id="newhour_start" > End: <input name="newhour_end[]" type="text" id="newhour_end" ><input name="newhour_day[]" type="hidden" id="newhour_day" value="Monday" >

Answers


You can insert multiple rows at once:

mysql_query("INSERT INTO hour 
            (hour_start,hour_end,hour_day) VALUES 
            (1, 2, 3),
            (4, 5, 6)
);

Need Your Help

Custom directive blocked

angularjs firefox-addon

I have defined a custom directive like this:

ruby on rails find_or_initialize

ruby-on-rails ruby ruby-on-rails-3

Is there any better way to achieve this in Ruby on Rails?