padams Posted August 31, 2007 Share Posted August 31, 2007 I've been struggling with a problem for a while and I think that the solution lies in the ability to create queries dynamically. On one page I have a number of drop-down menus created dynamically, so the number of menus can vary. Each drop-down represents a try/touchdown scored, and the user would select from the menu who scored it. On the next page I want to take the info entered and send it to the database, automatically creating new entries for each try/touchdown scored. The code I have come up with to create one try is below, but I'm not sure how to add multiple tries when the playerID will be changing for each drop-down menu. $createtry_sql = sprintf("INSERT into tries (tryOpponent, tryTeam, trySeason, tryPlayer) VALUES ('%s', '%s', '%s', '%s')", $_SESSION['creatematch']['opposition'], $_SESSION['creatematch']['ottersteam'], $_SESSION['creatematch']['season'], $_SESSION['creatematch']['playerID'] ); $createtry_query = mysql_query($createtry_sql) or die(mysql_error()); Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/67418-creating-queries-dynamically/ Share on other sites More sharing options...
scottybwoy Posted August 31, 2007 Share Posted August 31, 2007 Could you make it a bit clearer what you hope to achieve. Are you inserting multiple row data for each player Id or will you have many playerId and tries in one row? Quote Link to comment https://forums.phpfreaks.com/topic/67418-creating-queries-dynamically/#findComment-338456 Share on other sites More sharing options...
padams Posted September 2, 2007 Author Share Posted September 2, 2007 Inserting multiple data rows. The table I am inserting into (called 'tries') has a row for every try ever scored, and one of the columns in that table is the player who scored it. The drop-down menu that the user selects from will automatically create a new row in the 'tries' table, and I want it to take the player selected from the menu and put that value in the 'player who scored it (called tryPlayer)' column. Again, it wasn't too hard to do this for one try, but when there are a number of tries I run into problems. The problem gets more complicated as the number of tries varies for every game played, so that's why I think I need to create queries dynamically. Quote Link to comment https://forums.phpfreaks.com/topic/67418-creating-queries-dynamically/#findComment-339749 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.