Jump to content

Bradley99

Members
  • Posts

    148
  • Joined

  • Last visited

    Never

Everything posted by Bradley99

  1. Thanks for moving Kicken, also thanks for the help, worked perfect
  2. Hi, I have some code, which works, but not the way i wan't it too. The code should take win_points from each user in the BETTING table & Add them up, i.e giving the sum. Then the JOIN would display the username linking to the user_id from the betting table. What it's doing now is just displaying me (Admin - User ID #1) with the SUM of ALL win_points of EVERY user in the BETTING table. ANy idea's? Thanks <? $standing=mysql_query("SELECT username, SUM(b.win_points) as total_points FROM users AS u LEFT JOIN betting AS b ON b.user_id = id ORDER BY total_points"); while($the=mysql_fetch_object($standing)){ echo " <tr><td class='profilerow'>$the->username</td><td class='profilerow'>$the->total_points</td> </tr>"; } ?>
  3. Hi, I'm trying to fetch a number of columns from two different tables in a database. I'm using the following code to fetch the first set of info. . $showevent = mysql_query("SELECT * FROM fights WHERE event='$viewevent' AND id IN (SELECT fight_id FROM betting WHERE user_id='$user->id') ORDER by id ASC"); while($the=mysql_fetch_object($showevent)){ I need to use this code to fetch the second set: $showpick = mysql_query("SELECT * FROM betting WHERE event='$viewevent' AND user_id='$user->id'"); while($pick=mysql_fetch_object($showpick)){ I need the results in a table like so. . Red Corner - Blue Corner - Event - My Pick - Winner $the->f1 - $the->f2 - $viewevent - $pick->fighter_id - $pick->winner I need the results from the first query to MATCH the results from the second query. These can be matched by the fight_id from both tables. I just have no clue how to write the query for it.
  4. So. . if ($_POST['Submit']){ $category = $_POST['selectname']; { mysql_query("INSERT INTO category (`category`) VALUES ("'$category'')") or die (mysql_error()); mysql_query("INSERT INTO linkcategory (`category`) VALUES ("'$category'')") or die (mysql_error());
  5. With your IF Post submit code, I presume you'll have an INSERT INTO category. . . Just add another INSERT INTO underneath that to enter it into the other column.
  6. I've managed to do it a different way now, thanks for the help. Can anyone tell me if the bold part of this code is valid. . . $showevent = mysql_query("SELECT * FROM fights WHERE event='$viewevent' [b]AND id IN (SELECT fight_id FROM betting WHERE user_id='$user->id')[/b] ORDER by id ASC"); while($the=mysql_fetch_object($showevent)){
  7. Sorry, I'm terrible at explaining my problems. My question is basically how do I get them to align, please don't tell me i just add order by fight_id at the end of the second query?
  8. I am selecting from FIGHTS table WHERE the event column is $viewevent (this is determined by which event is selected by user) AND id (of the fight) column is in the BETTING table WHERE the users id is $user->id. Then order it by id. That sorts the first 3 columns in my code ($the-fighter1, $the-fighter2 & $viewevent). The next two i need fetching from the BETTING table. So i would use. . Select from BETTING table WHERE the event column is $viewevent AND the id of the fight is the same id as the corresponding result.
  9. That's because $the-> is used when fetching from the FIGHTS table. . . $viewpick is already determined in above code. The ones without any $the-> atall are the ones i need to be called from the BETTING table, But i Cannot figure out how to call from 2 tables in the same query, as the FIGHTS info needs to coincide with the BETTING info. So - Fighter1 vs Fighter 2 & Event are determined from the fights table, i then need to fetch the pick of which that user chose in the BETTING table (fighter_id) & the winner of that fight, again from the BETTING Table (winner), The two would be aligned by the fight_id.
  10. Hi guys, I'm having some problem with a piece of code, which should be displaying 5 things from 2 different tables. Here's my code: <? $showevent = mysql_query("SELECT * FROM fights WHERE event='$viewpick' AND id IN (SELECT fight_id FROM betting WHERE user_id='$user->id') ORDER by id ASC"); while($the=mysql_fetch_object($showevent)){ echo " <tr><td class='subtableheader' colspan='1'>Red Corner</td> <td class='subtableheader' colspan='1'>Blue Corner</td> <td class='subtableheader' colspan='1'>Event</td> <td class='subtableheader' colspan='1'>My Pick</td> <td class='subtableheader' colspan='1'>Winner</td></tr> <tr><td class='profilerow' colspan='1'>$the-fighter1</td> <td class='profilerow' colspan='1'>$the->fighter2</td> // Above 2 are fetched from the FIGHTS table. . <td class='profilerow' colspan='1'>$viewpick</td> //Below 2 should be fetched from BETTING table, but should coincide with the results from the FIGHTS table. <td class='profilerow' colspan='1'>$fighter_id</td> <td class='profilerow' colspan='1'>$winner</td></tr> </tr>"; } Any help is appreciated.
  11. I've read up quit alot on this but can't seem to get it to work. Basically what I wan't to do with the following code: <? $showevent = mysql_query("SELECT * FROM fights WHERE event='$viewevent' AND id NOT IN (SELECT fight_id FROM betting WHERE user_id='$user->id') ORDER by id ASC"); while($the=mysql_fetch_object($showevent)){ if($user->bonusp == "0") { $msg = "<form action='' method='post'> <tr> <td colspan='100%' class='TableHeading'> <b>$the->fighter1 Vs $the->fighter2</b></td> </tr> <tr><td class='profilerow' colspan='100%'><img src='http://fightclub.mmamount.com/eng/fighters/$the->fighter1.png' alt='$the->fighter1'/><img src='http://fightclub.mmamount.com/eng/fighters/versus.png' alt='VS'/><img src='http://fightclub.mmamount.com/eng/fighters/$the->fighter2.png' alt='$the->fighter2'/></td></tr> <tr><td class='profilerow' colspan='2%' align='left'><input type=radio name=fighter_id value=$the->fighter1> $the->fighter1 </td><td class='profilerow' colspan='20%'> <input type=radio name=fighter_id value=1> Draw</td><td class='profilerow' colspan='78%'> <input type=radio name=fighter_id value=$the->fighter2> $the->fighter2 </td></tr> <tr><td class='profilerow' colspan='3%'>Method:</td> <td class='profilerow' colspan='97%'><select name=method><option value=KO>Knockout</option><option value=TKO>TKO</option><option value=SUB>Submission</option><option value=DEC>Decision</option></select></td></tr> <tr><td class='profilerow' colspan='3%'>Round:</td> <td class='profilerow' colspan='97%'><select name=round><option value=1>1</option><option value=2>2</option><option value=3>3</option><option value=4>4</option><option value=5>5</option></select></td></tr> <tr><td class='profilerow' colspan='3%'>Use Bonus?</td> <td class='profilerow' colspan='97%'>You have 0 Bonus points to use</td> <input type='hidden' name='bonus' value='0'></tr> <input type='hidden' name='fight_id' value='$the->id'> <tr><td class='profilerow' colspan='3%'>Finished?</td> <td class='profilerow' colspan='97%'><input type='Submit' name='Submit2' value='Pick' class='Submit' /> </td></form> </tr>"; Is code it so that if Decision is chosen from Method, Then the Round selection is automated (Unchangeable) to be whatever the amount of rounds in the fights is, which will be determined by the rounds column in my fights table. Thanks
  12. Sorted, I keep wasting posts because 2 minutes later i figure the answers, goddam! I used $newbonus=$user->bonusp-$bonus; Then in query used SET bonusp = '$newbonus' Thanks
  13. Hi, I'm trying to update a table when a form is submitted, so that the column I'm updating is updated by minus one of the values in the form. Here's my update code: mysql_query("UPDATE users SET bonusp = 'bonusp-$bonus' WHERE id='$user->id'") or die (mysql_error()); $bonus has a value of either 0 or 1. When i submit with the code i have, it just sets the bonusp in users table to 0. Thanks
  14. Sorted it, Just added $viewevent=$_GET['viewevent']; $bonusdone = mysql_query("SELECT * FROM betting WHERE user_id='$user->id' AND fight_id='0'"); if ( mysql_num_rows( $bonusdone ) == 1 ) exit(); Right before the html code.
  15. Alright, I changed the code, and the if query works, but again it displays the code below when the query is true, so it displays the echo AND the code below. Full Code: <? $viewevent=$_GET['viewevent']; $bonusdone = mysql_query("SELECT * FROM betting WHERE user_id='$user->id' AND fight_id='0'"); if ( mysql_num_rows( $bonusdone ) == 1 ) echo "<table class='thinline' cellpadding='0' cellspacing='0' width='85%'> <tr> <td class='Tableheading'><font color='#ff8a00'><b>You have completed your Bonus Award picks for this event, please check back after '$fetch->date' to see your score.</b></font></td> </tr><tr><td class='subtableheader'>Make sure you've completed all your fight picks above</td></tr></table> <BR>"; else ?> <? if ($_POST['Submit1']){ $fotn_id = $_POST['fotn_id']; $sotn_id = $_POST['sotn_id']; $kootn_id = $_POST['kootn_id']; { mysql_query("INSERT INTO betting (`bet_id` , `event_id` , `fight_id` , `user_id` , `fighter_id`, `method`, `round`, `bonus`, `fotn_id`, `sotn_id`, `kootn_id`) VALUES ('', '$fetch->id', '0', '$user->id', '0', '0', '0', '0', '$fotn_id', '$sotn_id', '$kootn_id' )") or die (mysql_error()); $url = '?viewevent=$viewevent'; echo "Your bonus pick is in, Good Luck <META HTTP-EQUIV=Refresh CONTENT='1'; URL='.$url.'>"; }} ?> <table class="main" align"left" style='table-layout:fixed' cellpadding="2" cellspacing="0" rules="none" width="100%"> <col width=40> <col width=20> <col width=20> <col width=20> <tbody> <tr> <td colspan="4" align="left" class="TableHeading"> <b><?php echo "$viewevent"; ?> Bonus Picks</b></td> </tr> <tr> <td class="subtableheader" width="40%">Fight of the Night:</td> <td class="subtableheader" width="20%">KO of the Night:</td> <td class="subtableheader" width="20%">Submission of the Night:</td> <td class="subtableheader" width="20%">Finished:</td> </tr> <form action='' method='post'><tr> <td class="profilerow" ><select name="fotn_id"> <?php $select_fotn = mysql_query("SELECT id, fighter1, fighter2 FROM fights WHERE event='$viewevent' ORDER by id ASC"); while($the=mysql_fetch_object($select_fotn)){ echo "<option value=\"" .$the->id . "\">" .$the->fighter1 . _vs_ .$the->fighter2 . "</option>\r"; } ?> </select></td> <td class="profilerow"><select name="kootn_id"> <?php $select_sotn = mysql_query("SELECT id, fighter1, fighter2 FROM fights WHERE event='$viewevent' ORDER by id ASC"); while($the=mysql_fetch_object($select_sotn)){ echo "<option value=\"" .$the->fighter1 . "\">" .$the->fighter1 . "</option>\r <option value=\"" .$the->fighter2 . "\">" .$the->fighter2 . "</option>\r"; } ?> </select></td> <td class="profilerow" ><select name="sotn_id"> <?php $select_kootn = mysql_query("SELECT id, fighter1, fighter2 FROM fights WHERE event='$viewevent' ORDER by id ASC"); while($the=mysql_fetch_object($select_kootn)){ echo "<option value=\"" .$the->fighter1 . "\">" .$the->fighter1 . "</option>\r <option value=\"" .$the->fighter2 . "\">" .$the->fighter2 . "</option>\r"; } ?> </select></td> <input type='hidden' name='fight_id' value='$the->id'> <td class='profilerow'><input type='Submit' name='Submit1' value='Pick' class='Submit' /> </td></form> </tr></tbody></table> </center> </body> </html>
  16. I told you i was crap at explaining. If the first is true, the first echo should show, then exit. If the second if true, the second echo should show, then exit. If neither is true, the code displayed BELOW that PHP should show. But what's happening is, it's show BOTH the Echo & the code displayed below.
  17. It can only be one or the other, not first && second. So if it's first that is true, i need to exit after the first echo is that's possible.
  18. So, If either of the 2 if elseif's are true, then the rest of the page should die.
  19. Sup guys, I have some if elseif code to determine what should be shown if x = y (DUH). The if elseif part works fine. I.e if x=y then it echo's what it should, and if x=z it echo's what it should. But it ALSO displays what's underneath the if elseif. Here's the code: <? $pickdone = mysql_query("SELECT * FROM fights WHERE event='$viewevent' AND id NOT IN (SELECT fight_id FROM betting WHERE user_id='$user->id')"); $nofights = mysql_query("SELECT * FROM fights WHERE event='$viewevent'"); if ( mysql_num_rows( $nofights ) == 0 ) echo "<table class='thinline' cellpadding='0' cellspacing='0' width='85%'> <tr> <td class='Tableheading'><font color='#ff8a00'><b>There are currently no scheduled fights for this event, please check back soon.</b></font></td></tr></table> <BR>"; elseif ( mysql_num_rows( $pickdone ) == 0 ) echo "<table class='thinline' cellpadding='0' cellspacing='0' width='85%'> <tr> <td class='Tableheading'><font color='#ff8a00'><b>You have completed your picks for this event, please check back after '$fetch->date' to see your score.</b></font></td></tr></table> <BR>"; else ?> I tried adding an exit(); before the last else, but that doesn't work. Any help is appreciated. (Oh and i know I'm terrible at explaining my problems HA)
  20. I just used META refresh INSIDE the echo from the submit. Thanks anyway.
  21. Hi, I have 2 forms on a single page, After any of the forms are submitted, I would like the user to be re-directed straight back to the page they came from. My URL for the page is a .php?viewevent=$viewevent I don't know if that changes anything, but whatever i try, i cannot seem to get it to work.
  22. Thanks, I did try that but used Submit & submit (capital change) but didn't work, Submit1 & Submit2 does. Cheers. Would you know by anychance why when I submit the second form, the page reloads back to where it was, but if i submit the second form i get just an echo?
  23. Hi, I'm having trouble with having 2 if ($_POST['Submit']){ forms in 1 file. I have two forms(tables) in the file, Both of which update the same table but in different ways. So for example. Form 1 INSERTS into the first 9 columns dependant on what is picked from the form then the rest of the columns are set to default. And form 2 INSERTS a new row but only inserts into the last 4 columns, again dependant on what is picked from the form, with the other columns set to default. But what is happening when I hit 'Submit' on EITHER of the forms, It is creating 2 new rows, one with the info from the form I submitted, and 1 that is all defaults values from the second if ($_POST['Submit']){ form. Here's my code. if ($_POST['Submit']){ $viewevent = $_POST['event_id']; $fight_id = $_POST['fight_id']; $fighter_id = $_POST['fighter_id']; $method = $_POST['method']; $round = $_POST['round']; $bonus = $_POST['bonus']; $fotn_id = $_POST['fotn_id']; $sotn_id = $_POST['sotn_id']; $kootn_id = $_POST['kootn_id']; { mysql_query("INSERT INTO betting (`bet_id` , `event_id` , `fight_id` , `user_id` , `fighter_id`, `method`, `round`, `bonus`) VALUES ('', '$fetch->id', '$fight_id', '$user->id', '$fighter_id', '$method','$round','$bonus')") or die (mysql_error()); echo "You picked $fighter_id, Good Luck!"; } { mysql_query("INSERT INTO betting (`bet_id` , `event_id` , `fight_id` , `user_id` , `fighter_id`, `method`, `round`, `bonus`, `fotn_id`, `sotn_id`, `kootn_id`) VALUES ('', '$fetch->id', '0', '$user->id', '0', '0', '0', '0', '$fotn_id', '$sotn_id', '$kootn_id' )") or die (mysql_error()); echo "You picked $fighter_id, Good Luck!"; }} ?> I did try having the second forms PHP AFTER the first forms HTML, but that produces the same result. Thanks
  24. Had a thick moment. Sorted. If anyone has same problem, Just use 2 options. DUH!
×
×
  • 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.