Jump to content

floorfiller

Members
  • Posts

    18
  • Joined

  • Last visited

Everything posted by floorfiller

  1. thanks again Barand. I ended up doing something a little different, but your post definitely pointed me in the right direction.
  2. lol sorry about that Barand. so for instance let's say these are the two arrays: $adjusted = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 ,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78); $place12 = array(1,2,3,4,5,6,7,8,9,10,11,12); I would just want to subtract them with the array_diff function and rerun the while loop again using that new array value.
  3. Thanks Sen that is helpful. I'm getting close to what I'm looking for however it doesn't appear that the while loop is working quite the way i was expecting. if you see i was hoping to remove the players chance from the next iteration of the loop and select a new random number. I see that it keeps selecting numbers that are not in the array, which leads me to believe that it is not using the newly assigned array value correctly. any thoughts?
  4. Hello Everyone, I am working on a little project, which is basically creating a lottery draft order for our fantasy football league (I know uber cool right? lol). I'm basically trying to mimic the old NBA draft lottery by doing something like the following: Say our league has 12 teams and I want to weight each players chance of getting that 1st pick in the draft? Well I would give the worst player 12 chances out of 78, 2nd to last 11 chances out of 78 etc. So I basically created an array with values 1-78 to be my overall chances and some other arrays to assign numbers to each team member i.e. 1-12 to last place, 13-23 for send to last etc. and I was planning to do a while loop and array_diff to narrow down the chances. here is what i have thus far: while($x <= 12){ $num = $adjusted[mt_rand(0,count($adjusted)-1)]; Switch($num){ case in_array($num,$place12): echo $x + ' ' + 'Player12'; $adjusted = array_diff($adjusted,$place12); $x++; break; case in_array($num,$place11): echo $x + ' ' + 'Player11'; $adjusted = array_diff($adjusted,$place11); $x++; break; case in_array($num,$place10): echo $x + ' ' + 'Player10'; $adjusted = array_diff($adjusted,$place10); $x++; break; case in_array($num,$place9): echo $x + ' ' + 'Player9'; $adjusted = array_diff($adjusted,$place9); $x++; break; case in_array($num,$place8): echo $x + ' ' + 'Player8'; $adjusted = array_diff($adjusted,$place8); $x++; break; case in_array($num,$place7): echo $x + ' ' + 'Player7'; $adjusted = array_diff($adjusted,$place7); $x++; break; case in_array($num,$place6): echo $x + ' ' + 'Player6'; $adjusted = array_diff($adjusted,$place6); $x++; break; case in_array($num,$place5): echo $x + ' ' + 'Player5'; $adjusted = array_diff($adjusted,$place5); $x++; break; case in_array($num,$place4): echo $x + ' ' + 'Player4'; $adjusted = array_diff($adjusted,$place4); $x++; break; case in_array($num,$place3): echo $x + ' ' + 'Player3'; $adjusted = array_diff($adjusted,$place3); $x++; break; case in_array($num,$place2): echo $x + ' ' + 'Player2'; $adjusted = array_diff($adjusted,$place2); $x++; break; case in_array($num,$place1): echo $x + ' ' + 'Player1'; $adjusted = array_diff($adjusted,$place1); $x++; break; default: $adjusted = $lottery; break; } } Just starting out on the project so it's still pretty basic. Just trying to work on functionality right now. I am getting an undefined offset error which i assume is related to the way i'm doing and storing the mt_rand value. any thoughts on how i might fix it?
  5. wow i'm a moron. sorry guys i just answered my own question. it seems in the <select> statement i forgot to close the braces on the 2nd one. and that is throwing things off. sorry i'd delete the post, but i didn't see a delete button.
  6. Hey everyone, Been a while since I posted. I hope everyone is doing well. I've built a couple of for() loops into my program and I'm getting some inconsistent results. The first loop I made was just a simple counter looking like this: <select name="event_name"> <?php for($x = 1; $x <= 50; $x++){ if($x < 10){ echo "<option value=\"$x\">Event 0$x:"; echo "</option>"; } else{ echo "<option value=\"$x\">Event $x:"; echo "</option>"; } } ?> </select> This code works perfect. The 1st entry in my drop down list is event 1, then event 2 etc. now i have basically the same code on the another selection: <select name="date" <?php for($x = 1; $x <= 24; $x++){ if($x < 10){ echo "<option value=\"$x\">0$x:00 EST"; echo "</option>"; } else{ echo "<option value=\"$x\">$x:00 EST"; echo "</option>"; } } ?> </select> however the generated code on this call starts with a result on 2 instead of 1 giving me 02:00 EST instead of 01:00 EST. I'm sure I could work around this by declaring some additional variables, but i'm just trying to figure out why i'm seeing different results between these two loops? any thoughts? thanks in advance for your help
  7. also note that I quoted a little differently. One of the things I had trouble with was just the stupid syntax details. As Pickachu mentioned:
  8. Hello svabhishek, The first thing I noticed when looking at your code is the query looks to be a little off. I would change that to this: $query = "INSERT INTO `profs` (`rating`) VALUES ('$rating')"; Remember that you named your POST data to a variable called $rating. That's the variable that holds the VALUES that you're inputting. That would be the first thing I'd change. Do that and let us know if you still have any issues.
  9. Hey guys, I got another one that i could use some help on. I have a input form that utilizes a javascript that adds additional rows to my table. here is a look at what i got. <script type="text/javascript"> function insertRow() { var x = document.getElementById('results_table').insertRow(-1); var a = x.insertCell(0); var b = x.insertCell(1); var c = x.insertCell(2); var d = x.insertCell(3); var e = x.insertCell(4); a.innerHTML="<input type=\"text\" name=\"id\">"; b.innerHTML="<input type=\"text\" name=\"place\">"; c.innerHTML="<input type=\"text\" name=\"username\">"; d.innerHTML="<input type=\"text\" name=\"earnings\">"; e.innerHTML="<input type=\"button\" value=\"delete\" onClick=\"deleteRow(this)\">"; } function deleteRow(r) { var i=r.parentNode.parentNode.rowIndex; document.getElementById('results_table').deleteRow(i); } </script> this is my code stored in the header of my page. basically just a button to add a new row and a button in each row to delete rows if needed. here is a look at my html table, pretty basic... <table id="results_table"> <th>Event ID</th><th>Place</th><th>Username</th><th>Earnings</th> <tr> <td><input type="text" name="id"></td><td><input type="text" name="place"></td><td><input type="text" name="username"></td><td><input type="text" name="earnings"></td><td><input type="button" value="delete" onClick="deleteRow(this)"</td> </tr> </table> Now what I am hoping to acheive is once i submit all of these rows to the database i will insert each of these rows into their own row in the database. is this doable? the structure of my database is: ResultID (Primary Key) Place Earnings UserID (Foreign Key) EventID (Foreign Key) now i think the biggest problem i'm having with submitting data to the database is that in the original HTML form I am typing in the actual username and not the userID. so when it comes to processing I need to do a switch of these two things before I run my query. Should something like this work? $username = $_POST['username']; $userID = "SELECT userID FROM users WHERE username="$username"; $query = mysql_query($userID); also i've never tried to submit multiple entries at a time. maybe i have to create an array somehow in order to capture each rows data. any thoughts? as always thanks for the help.
  10. give me just a moment i think i have some code written up for this... here is the PHP portion... <?php $connect = mysql_connect('localhost' , 'root' , '') or die(); $db = mysql_select_db('database') or die(); $select = "SELECT genreID , genre_type FROM genre"; $result = mysql_query($select); $options = ""; While ($row = mysql_fetch_array($result)) { $genreID = $row["genreID"]; $genre = $row["genre_type"]; $options .= "<option=\"$genreID\">".$genre; } ?> Here is the HTML portion... <html> <table> <th>Genre</th> <tr> <td><select name="genres"><?php echo $options; ?></td> </tr> </table> </html>
  11. thanks again Pikachu. that fixed it. sorry for such basic problems. i'm trying to self teach all this stuff.
  12. thanks dcro, but i've tried it both ways. still getting this error
  13. Hey Pikachu, Thank you for your continued help. Here is the error message i received. I tried doing a couple of things including taking out the userID and NULL fields, but i get this same basic error still.
  14. hey everyone, sorry to open this back up, but i am having a very similar problem with another form that i've made. please take a look at this one as well. I've been looking around online and seeing some ways of maybe doing this, but Net Beans keeps telling me the syntax is wrong. here is my html form. i think this is the problem. once again i don't think i'm setting the variables correctly: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> </head> <body> <form action='signup.php' method='post'> <table> <tr> <td>Username: </td><td><input type='text' name='username' value=""></td> </tr> <tr> <td></td><td></td> <tr> <td>Email: </td><td><input type='text' name='email' value=""></td> </tr> <tr> <td>Country: </td><td><select name='country'> <option value="1">United States</option> <option value="2">Canada</option> </select></td> </tr> <tr> <td>Password: </td><td><input type='password' name='password' value=""></td> </tr> <tr> <td></td><td></td> </tr> <tr> <td></td><td><input type='submit' name="submit" value='Join Now'></td> </tr> </table> </form> </body> </html> and here is my php form. this should be ok it seems to be working properly just the variables aren't been recognized. <?php $username = $_POST['username']; $email = $_POST['email']; $country = $_POST['country']; $password = $_POST['password']; $connect = mysql_connect('localhost','root', '') or die('can not connect to localhost'); if ($connect) { echo 'connected'; } $db = mysql_select_db('dpl') or die('can not connect to DPL'); if ($db) { echo 'DPL selected'; } $query = mysql_query("INSERT INTO users ('userID' , 'username' , 'email' , 'password' , 'countryID') VALUES (NULL , '$username' , '$email' , '$password' , '$country' )"); if (mysql_affected_rows()) { echo "Thank you for Registering"; } ?> now looking around I've seen a couple of things that might solve this problem. similarly to my last issue i think it has to do with the variables not being assigned a value. i saw in one tutorial to do something similar to this: but i am not getting this to work properly. i think the syntax is in error. if anyone has any ideas i would appreciate it
  15. AHA!! thank you very much sir. I've got it working great now. such a simple solution I probably never would've found it. thanks again
  16. hey guys, alright appreciate the help thus far. Paul Ryan I did make your change, however it still isn't working. I think because the form isn't passing the variables correctly i dunno. here is the code for my form: <html> <form action="create_event.php" method="post"> <table> <th>Season</th><th>Month</th><th>Day</th><th>Year</th><th>Time</th><th>Event</th><th>Game</th><th>Buy-In</th> <tr> <td><select name="season"> <option>Season 01:</option> <option>Season 02:</option> </select></td> <td><select name="month"> <option>January</option> <option>February</option> <option>March</option> <option>April</option> <option>May</option> <option>June</option> <option>July</option> <option>August</option> <option>September</option> <option>October</option> <option>November</option> <option>December</option> </select></td> <td><select name="day"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> <option>15</option> <option>16</option> <option>17</option> <option>18</option> <option>19</option> <option>20</option> <option>21</option> <option>22</option> <option>23</option> <option>24</option> <option>25</option> <option>26</option> <option>27</option> <option>28</option> <option>29</option> <option>30</option> <option>31</option> </select></td> <td><select name="year"> <option>2011</option> <option>2012</option> </select></td> <td><select name="time"> <option>00:00 EST</option> <option>01:00 EST</option> <option>02:00 EST</option> <option>03:00 EST</option> <option>04:00 EST</option> <option>05:00 EST</option> <option>06:00 EST</option> <option>07:00 EST</option> <option>08:00 EST</option> <option>09:00 EST</option> <option>10:00 EST</option> <option>11:00 EST</option> <option>12:00 EST</option> <option>13:00 EST</option> <option>14:00 EST</option> <option>15:00 EST</option> <option>16:00 EST</option> <option>17:00 EST</option> <option>18:00 EST</option> <option>19:00 EST</option> <option>20:00 EST</option> <option>21:00 EST</option> <option>22:00 EST</option> <option>23:00 EST</option> <option>24:00 EST</option> </select></td> <td><select name="event"> <option>Event 01:</option> <option>Event 02:</option> <option>Event 03:</option> <option>Event 04:</option> <option>Event 05:</option> <option>Event 06:</option> <option>Event 07:</option> <option>Event 08:</option> <option>Event 09:</option> <option>Event 10:</option> </select></td> <td><select name="game"> <option>No Limit Hold'em</option> <option>No Limit Hold'em - Heads up</option> <option>No Limit Hold'em - Short Handed</option> <option>No Limit Hold'em - Shootout</option> </select></td> <td><select name="buyin"> <option>Freeroll</option> <option>Invite Only</option> <option>$5.00 + $.50</option> <option>$10.00 + $1</option> <option>$20.00 + $2</option> </select></td> <td><input type="submit" value="Submit"></td> </tr> </table> </form> </html> in an effort to try and isolate the problem i just tried to name a variable from my form and echo it such as: $season = $_POST['season']; echo $season; and I get the following error message: i guess i can only assume then that my form isn't passing along the variables correctly yes? any further help is appreciated
  17. Ok I've been working on this a little more and I'm starting to think that the issue is that my POST variables are not being passed along properly. Does anyone know if there is something special that needs to be done in order to pass a drop down list variable to the php page?
  18. Hey guys, New to the forum and a newer user of PHP / MySQL. I am having trouble with some code I've written up. I don't seem to get any errors when running it, but it's not updating my database the way that it should. hopefully a simple fix. I am thinking that it must be on the MySQL side of things. Couple of things to start. My html form is comprised completely of drop down list inputs. I'm the only user so I thought this would be the easiest approach. Because of that I've made my PHP as follows: <?php $season = $_POST['season']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $time = $_POST['time']; $event = $_POST['event']; $game = $_POST['game']; $buyin = $_POST['buyin']; $connect = mysql_connect('localhost','root','') or die('can not connect'); if ($connect) { echo "connected to database"; } $db = mysql_select_db('dpl') or die('can not find database'); if ($db) { echo "DPL Selected"; } $query = sprintf("INSERT INTO events (season , month , day , year , time , event , game , buyin) VALUES ('%s' , '%s' , '%s' , '%s' , '%s' , '%s' , '%s' , '%s')", $season , $month , $day , $year , $time , $event , $game , $buyin ); if ($query) { echo "Your event has been added"; } ?> My connection is working, my database is selected and I'm even now getting confirmation that my query is working, but when i go to check my database there are no entries in it? any thoughts? I've tried the drop down variables as both VARCHAR and TEXT inputs in MySQL, but I can't seem to get it to work. Any help is greatly appreciated.
×
×
  • 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.