mytwocents All American 20654 Posts user info edit post |
OK, I'm attempting to put together a top 25 college hoops poll to do with my friends. I've got the database set up, and I can insert the data via the mysql terminal and it works just fine. Here's my table structure: table-users: userid, username
table-teams teamid, teamname
table-votes userid, teamid, position, timestamp
Now logically speaking, I'd basically be wanting to do this:
for each "position" (1 being the first pull down, 25 being the last) insert that position number (1-25) for the team chosen and apply it to the 'username' chosen in the 'username' pulldown menu.
Now if I were inserting via the terminal, the statement would look like this: (I shortened it to 10 teams/10 positions for the sake of making this shorter)
insert into votes (uid, tid, pos) values (1, 5,1), (1,10,2), (1,2,3), (1,7,4), (1,6,5), (1,9,6), (1,1,7), (1,3,8), (1,4,9), (1,8,10);
The first number would be whatever usernameid was chosen, in this case "1" the second number would be the teamid (which would show in the pulldowns as the actual team name, not the id number) and the third number would be what place said team was in according to that person. Now how the hell can I get this into a form...??? I know loops, or arrays or whatever, but I'm not a coding expert and this is all in fun so who wants to be a hero? 12/23/2006 7:43:27 PM |
BigMan157 no u 103354 Posts user info edit post |
for the form part
<form name="form" action="<?PHP print $PHP_SELF; ?>" method="post"> <select> ... </select> <input type="submit" name="sub" value="WORDS ON THE BUTTON"> </form>
name the dropdowns team[#] where # is a number (ex. team[5])
<select name="team[0]"> <option value="1">1</option> <option value="2">2</option> ... <option value="25">25</option> </select>
then put some php code above the actual html code of the page that says
if($sub) { for($i=1; $i<=25; $i++) { query="insert into votes (uid, tid, pos) values (1, $i, team[$i])"; //db code goes here } }
you may need to use $_POST['team[$i]'] instead of team[$i] tho
[Edited on December 23, 2006 at 9:26 PM. Reason : something like that]12/23/2006 9:13:29 PM |
mytwocents All American 20654 Posts user info edit post |
you guys rock. Seriously....but OK wait......for my initial php code, wouldn't I want instead of the number 1 (for the uid) it should rather be something along the lines of $_POST['uid'] ?
if($sub) { for($i=1; $i<=25; $i++) { query="insert into votes (uid, tid, pos) values (1, $i, $_POST['team[$i]'])"; mysql_connect("localhost","login****","password****") or die("Unable to connect to SQL server"); mysql_select_db("ncaahoops") or die("Unable to select database"); mysql_query($query) or die("Insert Failed!"); } ?>
and then for my form....I'm a little lost because I need the 1st pulldown to be the username so something like:
|