Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/67418-creating-queries-dynamically/
Share on other sites

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.

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.