Dethman Posted January 22, 2009 Share Posted January 22, 2009 Hey guys I need help doing something like this: <?php for ($i=0;$i<=15;$i++){ //The above FOR statement will start the code to cycle through the name and gender arrays that we set in the form. //If there's a name entered, insert the names into the database. $query = 'insert into players (`GameID`, `name`, `sex`, `score`) values ('$GameID', '$player".$i."', '$sex".$i."', '0')'.$i; // The Below Code is for the query number to be queried over an over again! mysql_query ($query."".$i.""); //The below echo statement is here so you can see that the code is working. Delete it when the site is ready to go live. //end else } //end for loop ?> Any Help Would be Awesome Quote Link to comment https://forums.phpfreaks.com/topic/142018-hey-guys-for-loop-var-naming/ Share on other sites More sharing options...
The Little Guy Posted January 22, 2009 Share Posted January 22, 2009 so... what is the problem your having? Quote Link to comment https://forums.phpfreaks.com/topic/142018-hey-guys-for-loop-var-naming/#findComment-743639 Share on other sites More sharing options...
MadTechie Posted January 22, 2009 Share Posted January 22, 2009 I may be on the wrong track here but wouldn't this be easier ? <?php foreach($_POST as $P) { if(!empty($P['NAME'])) { mysql_query ("insert into players (`GameID`, `name`, `sex`, `score`) values ('$GameID', '{$P['player']}', '{$P['sex']}', '0')"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/142018-hey-guys-for-loop-var-naming/#findComment-743642 Share on other sites More sharing options...
Dethman Posted January 22, 2009 Author Share Posted January 22, 2009 It isnt working can someone modify my code because my if(!empty) { } are already cycled before this loop Quote Link to comment https://forums.phpfreaks.com/topic/142018-hey-guys-for-loop-var-naming/#findComment-743645 Share on other sites More sharing options...
Dethman Posted January 22, 2009 Author Share Posted January 22, 2009 To be more exact it isnt quering and I need to know if the $query = 'QUERY'.$i; is correct? Quote Link to comment https://forums.phpfreaks.com/topic/142018-hey-guys-for-loop-var-naming/#findComment-743647 Share on other sites More sharing options...
The Little Guy Posted January 22, 2009 Share Posted January 22, 2009 just to add on to yours to make it easier on the database... <?php $in = "insert into players (`GameID`, `name`, `sex`, `score`) values"; foreach($_POST as $P) { if(!empty($P['NAME'])) { $in .= ' (\''.$GameID.'\', \''.$player.$i.'\', \''.$sex.$i.'\', \'0\'),'; } } mysql_query(rtrim($in,','))or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/142018-hey-guys-for-loop-var-naming/#findComment-743650 Share on other sites More sharing options...
trq Posted January 22, 2009 Share Posted January 22, 2009 Your code makes little sense. What do these name and gender arrays you speak of look like? Quote Link to comment https://forums.phpfreaks.com/topic/142018-hey-guys-for-loop-var-naming/#findComment-743667 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.