Jump to content

Loop through sql query


denoteone

Recommended Posts

Is it ok to run a for loop to insert data into a database?

 

I have

$sql="INSERT INTO prices (box0,box1,box2,box3,box4,box5,box6,box7,box8,box9,box10,box11,box12,box13,box14,box15,box16,box17,box18,box19,box20,box21,box22,box23,box24,box25,box26,box27,box28,box29,box30,box31,box32,box33,box34,box35,box36,box37,box38,box39,box40,box41,box42,box43) VALUES ('$box_0','$box_1','$box_2','$box_3','$box_4','$box_5','$box_6','$box_7','$box_8','$box_9','$box_10','$box_11','$box_12','$box_13','$box_14','$box_15','$box_16','$box_17','$box_18','$box_19','$box_20','$box_21','$box_22','$box_23','$box_24','$box_25','$box_26','$box_27','$box_28','$box_29','$box_30','$box_31','$box_32','$box_33','$box_34','$box_35','$box_36','$box_37','$box_38','$box_39','$box_40','$box_41','$box_42','$box_43')"; 

mysql_query($sql) or die(mysql_error()); 

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die(mysql_error()); 

 

it would be less of a mess if i could loop through it but I am not sure if this is good practice or not. Any thoughts would be awesome.

 

 

Link to comment
Share on other sites

For this function I have a menu board GUI that has 43 areas to add pricing. each row has a column for that pricing area. Does this make sense? Each row would be an update made to the pricing fields.

 

If there is a better way of doing this please let me know. Thanks for your help.

 

 

Link to comment
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.