Jump to content

floorfiller

Members
  • Posts

    18
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

floorfiller's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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
×
×
  • 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.