barkster Posted September 1, 2005 Share Posted September 1, 2005 I'm trying to do a multiple row insert from a form using field names Name1, Name2, Description1, Description2, etc... How do I build something like a ForEach 1 to 10 statement to use for my insert. I was going try something like Foreach i 1 to 10 insert Description & i etc.. don't know the syntax of course but from what I found I had to build an array then use the array in the foreach command. Is there no way to tell it 1 to 10 or something like that? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/2478-foreach-1-to-10/ Share on other sites More sharing options...
obsidian Posted September 1, 2005 Share Posted September 1, 2005 I'm trying to do a multiple row insert from a form using field names Name1, Name2, Description1, Description2, etc... How do I build something like a ForEach 1 to 10 statement to use for my insert. I was going try something like Foreach i 1 to 10 insert Description & i etc.. don't know the syntax of course but from what I found I had to build an array then use the array in the foreach command. Is there no way to tell it 1 to 10 or something like that? Thanks 273630[/snapback] if you know how many fields there are, use for() instead of foreach(): [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--] [span style=\"color:#0000BB\"]<?php [/span][span style=\"color:#007700\"]for ([/span][span style=\"color:#0000BB\"]$i [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]1[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$i [/span][span style=\"color:#007700\"]<= [/span][span style=\"color:#0000BB\"]10[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$i[/span][span style=\"color:#007700\"]++) { echo [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\"Name$i\"[/span][span style=\"color:#007700\"]]; } [/span][span style=\"color:#0000BB\"]?> [/span] [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] Quote Link to comment https://forums.phpfreaks.com/topic/2478-foreach-1-to-10/#findComment-8231 Share on other sites More sharing options...
barkster Posted September 1, 2005 Author Share Posted September 1, 2005 Thanks, that's exactly what I needed. I appreciate it. if you know how many fields there are, use for() instead of foreach(): [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--] [span style=\\\"color:#0000BB\\\"]<?php for [/span][span style=\\\"color:#007700\\\"]([/span][span style=\\\"color:#0000BB\\\"]$i [/span][span style=\\\"color:#007700\\\"]=[/span][span style=\\\"color:#0000BB\\\"] 1[/span][span style=\\\"color:#007700\\\"];[/span][span style=\\\"color:#0000BB\\\"] $i [/span][span style=\\\"color:#007700\\\"]<=[/span][span style=\\\"color:#0000BB\\\"] 10[/span][span style=\\\"color:#007700\\\"];[/span][span style=\\\"color:#0000BB\\\"] $i[/span][span style=\\\"color:#007700\\\"]++)[/span][span style=\\\"color:#0000BB\\\"] [/span][span style=\\\"color:#007700\\\"]{ [/span][span style=\\\"color:#0000BB\\\"] echo $_POST[/span][span style=\\\"color:#007700\\\"][[/span][span style=\\\"color:#DD0000\\\"]\\\"Name$i\\\"[/span][span style=\\\"color:#007700\\\"]]; } [/span][span style=\\\"color:#0000BB\\\"]?>[/span] [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] 273636[/snapback] Quote Link to comment https://forums.phpfreaks.com/topic/2478-foreach-1-to-10/#findComment-8233 Share on other sites More sharing options...
obsidian Posted September 1, 2005 Share Posted September 1, 2005 Thanks, that's exactly what I needed. I appreciate it. 273657[/snapback] that's what we're here for! ;-) i'll mark this topic solved Quote Link to comment https://forums.phpfreaks.com/topic/2478-foreach-1-to-10/#findComment-8234 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.