PHP - Php Bracket Maker
Okay right now I have a form that pulls all the values I need and sends it to a separate page, except here is where I run into the problem. I logically have no idea who to write it. I have an array called $teamname that holds all the team names. What I need to do is make it dynamically create the table rows according to how many teams their are and then put the teams against each other like 1v8, 2v7. Here is my script that allows the bracket to work, I just need to convert it to dynamically work
<script> function win(winner) { var team = winner.value; var levels = winner.name.substring(3).split("_"); var curlevel = parseInt(levels[0]); var curgame = parseInt(levels[1]); var nextlevel = curlevel + 1; var nextgame = Math.floor( (curgame+1) / 2 ); var winnerButton = winner.form.elements["WIN"+nextlevel+"_"+nextgame]; if ( winnerButton == null ) return; ++nextlevel; nextgame = Math.floor( (nextgame+1) / 2 ); var nextButton = winner.form.elements["WIN"+nextlevel+"_"+nextgame]; var forward = ( nextButton != null && nextButton.value == winnerButton.value ); winnerButton.value = team; if ( forward ) winnerButton.click( ); } </script> <?php $schedule=$_POST['schedule']; if($schedule=="season") { $teams=$_POST['teams']; $schedule=$_POST['schedule']; $teamname = unserialize(urldecode($_POST["teamname"])); $games=$_POST['games']; $times=$_POST['times']; } if($schedule=="playoffs") { $teams=$_POST['teams']; $schedule=$_POST['schedule']; $teamname = unserialize(urldecode($_POST["teamname"])); $games=$_POST['games']; $times=$_POST['times']; $result = count($teamname); ?> <form> <table border=0 cellpadding=3> <tr> <td><input type=button class="team" name="WIN0_1" onclick="win(this)" value="Amherst"></td> </tr> <tr> <td></td> <td><input type=button class="team" name="WIN1_1" onclick="win(this)" value=""></td> </tr> <tr> <td><input type=button class="team" name="WIN0_2" onclick="win(this)" value="Bowling Green"></td> </tr> <tr> <td> </td> <td> </td> <td><input type=button class="team" name="WIN2_1" onclick="win(this)" value=""></td> </tr> <tr> <td><input type=button class="team" name="WIN0_3" onclick="win(this)" value="Connecticut"></td> </tr> <tr> <td></td> <td><input type=button class="team" name="WIN1_2" onclick="win(this)" value=""></td> </tr> <tr> <td><input type=button class="team" name="WIN0_4" onclick="win(this)" value="Duke"></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td><input type=button class="team" name="WIN3_1" onclick="win(this)" value=""></td> </tr> <tr> <td><input type=button class="team" name="WIN0_5" onclick="win(this)" value="Elmira"></td> </tr> <tr> <td></td> <td><input type=button class="team" name="WIN1_3" onclick="win(this)" value=""></td> </tr> <tr> <td><input type=button class="team" name="WIN0_6" onclick="win(this)" value="Florida"></td> </tr> <tr> <td> </td> <td> </td> <td><input type=button class="team" name="WIN2_2" onclick="win(this)" value=""></td> </tr> <tr> <td><input type=button class="team" name="WIN0_7" onclick="win(this)" value="Georgetown"></td> </tr> <tr> <td></td> <td><input type=button class="team" name="WIN1_4" onclick="win(this)" value=""></td> </tr> <tr> <td><input type=button class="team" name="WIN0_8" onclick="win(this)" value="Hawaii"></td> </tr> </table> </form> <? } ?> Similar TutorialsBeen trying to figure out...how can I delete the first input field box in a series?
Under Presentations Requested, I want the delete the first short box.
http://myiwma.org/wo...servation-form/
Lauren
I am trying to achieve something that appears simple but I spent few hours in vain Quote $tag1 = '<a href="layout_m.php?k='.$k.'&name='.$name.'&type='.$type.'">'; if ($k=="1") {$history = ucfirst($name) . ' - ' . $tag1 . $k .'</a>' ; } else {$history = $history . ' - '. $tag1 . $k . '</a>' ;} print $history; This is part of a page which is involved in passing data by forms or/and URL (eg layout.php?k=1) and the display of the page depends on k. At k=1,(first page) things are ok [Joe - <a href="layout_m.php?k=1&name=Joe&type=genus"> 1 </a>] but on passing to the next page, the output is not as desired part of the variable is escaped out on the browser and breaks the variable content View source gives this: Joe - <a href= - <a href="layout_m.php?k=3&name=Joe&type=genus"> 1 </a> while I want: Joe - <a href="layout_m.php?k=1&name=Joe&type=genus"> 1 </a> - <a href="layout_m.php?k=3&name=Joe&type=genus"\> 3 </a> What I achieve to do is a simple history based on an accumulation of k EG Joe - 1 - 3 - 5 - 6 - 8 Where each number (k) is linked and when pressed each go to the corresponding keypage. Hello, I 've been coding in php for some time now but am not sure where the end bracket on a while loop is supposed to be situated. For example: Code: [Select] $get = mysql_query("SELECT * FROM members WHERE username='$user'"); while($row = mysql_fetch_array($get)) { $balance = $row["balance"]; } $new_balance = $balance + $deposit; OR is the above script supposed to be like this (the end bracket has changed position) Code: [Select] $get = mysql_query("SELECT * FROM members WHERE username='$user'"); while($row = mysql_fetch_array($get)) { $balance = $row["balance"]; $new_balance = $balance + $deposit; } Hi Guys, Happy new year to all!! I'm trying to make starcraft 2 tournament web site for me and friends. i stuck on tournament system. I have a jquery script that makes a bracket but I couldn't figure out how can I implament it with my database and php:( I would like to ask you some questions please. I have this html and jquery script. my mysql database is like this tournamenttree id - UserID - TournamentID - Round 1 - 1 - 1 - 1 2 - 15 - 1 - 1 3 - 17 - 1 - 1 4 - 25 - 1 - 1 and tournaments id - tournamentname - createdtime - players - active 1 -Sunday Cup - time() - 4 - 1 and Users table Code: [Select] <?php $link = mysql_connect( '', ', ' ); if ( !is_resource( $link ) ) die( 'MySQL Connect Error' ); if ( !mysql_select_db( 'db6968_game', $link ) ) die( 'MySQL DB Error' ); mysql_query( "SET CHARACTER SET UTF8" ); mysql_query( "SET collation_connection = 'utf8_turkish_ci'" ); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us"> <head> <title>MyTournamentName</title> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' type='text/javascript'> </script> <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js' type='text/javascript'> </script> <style type="text/css"> .tournament { background-color: #F0F0F0; border: dashed 1px solid; overflow: auto; } .tournament .bracket { background-color: #DFDFDF; min-width: 100px; vertical-align: top; float: left; } .tournament .bracket .match { background-color: #D0D0D0; border-top: 1px solid; border-right: 1px solid; border-bottom: 1px solid; } .tournament .bracket .match .p1 { height: 20px; } .tournament .bracket .match .p2 { height: 20px; } .tournament .bracket .match .spacer { background-color: #DFDFDF; height: 38px; } .tournament .bracket .spacer { height: 80px; } .tournament .bracket .half-spacer { height: 40px; } .tournament .bracket .small-spacer { height: 10px; background-color: #F1F1F1; } .tournament .bracket .winner { border-bottom: 1px solid; } .left-line { border-left: 1px solid; } .tournament .cell { min-width: 100px; height: 20px; float: left; background-color: #DFDFDF; } .tournament .l2 { background-color: #D0D0D0; } .tournament .lmax { width: 0px; clear: both; } </style> <script type="text/javascript"> var matchInfo = { "rounds" : [ { "name": "Round1", "matches" : [ { "id" : 1, "p1" : "mTwDeMuslim", "p2" : "Luffy" }, { "id" : 2, "p1" : "SeleCT", "p2" : "NEXGenius" }, { "id" : 3, "p1" : "Fenix", "p2" : "SoftBall" }, { "id" : 4, "p1" : "White-Ra", "p2" : "Ice" }, { "id" : 5, "p1" : "HuK", "p2" : "RedArchon" }, { "id" : 6, "p1" : "Capoch", "p2" : "Loner" }, { "id" : 7, "p1" : "mTwDIMAGA", "p2" : "MakaPrime" }, { "id" : 8, "p1" : "TLAF-Liquid`TLO", "p2" : "SEN" } ] }, { "name": "Round2", "matches" : [ { "id" : 9, "p1" : null, "p2" : null }, { "id" : 10, "p1" : null, "p2" : null }, { "id" : 11, "p1" : null, "p2" : null }, { "id" : 12, "p1" : null, "p2" : null } ] }, { "name": "Round3", "matches" : [ { "id" : 13, "p1" : null, "p2" : null }, { "id" : 14, "p1" : null, "p2" : null }, ] }, { "name": "Round4", "matches" : [ { "id" : 15, "p1" : null, "p2" : null }, ] } ] }; $(document).ready(function($) { var base = $('#writeHere'); var matchDivsByRound = []; for (var roundIndex=0; roundIndex<matchInfo.rounds.length; roundIndex++) { var round = matchInfo.rounds[roundIndex]; var bracket = checkedAppend('<div class="bracket"></div>', base); var matchDivs = []; matchDivsByRound.push(matchDivs); //setup the match boxes round by round for (var i=0; i<round.matches.length; i++) { var vOffset = checkedAppend('<div></div>', bracket); var match = round.matches[i]; var matchHtml = '<div class="match" id="match' + match.id + '">' + '<div class="p1">' + fmtName(match.p1) + '</div>' + '<div class="spacer"></div>' + '<div class="p2">' + fmtName(match.p2) + '</div>'; matchDiv = checkedAppend(matchHtml, bracket); matchDivs.push(matchDiv); if (roundIndex > 0) { //row 2+; line up with previous row var alignTo = matchDivsByRound[roundIndex-1][i*2]; //offset to line up tops var desiredOffset = alignTo.position().top - matchDiv.position().top; //offset by half the previous match-height desiredOffset += alignTo.height() / 2; vOffset.height(desiredOffset); } else { checkedAppend('<div class="small-spacer"></div>', bracket); } if (roundIndex > 0) { //tweak our size so we stretch to the middle of the appropriate element var stretchTo = matchDivsByRound[roundIndex-1][i*2+1]; var newH = stretchTo.position().top + stretchTo.height()/2 - matchDiv.position().top; var deltaH = newH - matchDiv.height(); matchDiv.height(newH); var spacer = matchDiv.find('.spacer'); spacer.height(spacer.height() + deltaH); } } } //setup the final winners box; just a space for a name whose bottom is centrally aligned with the last match bracket = checkedAppend('<div class="bracket"></div>', base); var vOffset = checkedAppend('<div></div>', bracket); var alignTo = matchDivsByRound[matchInfo.rounds.length - 1][0]; //only 1 match in the last round var html = '<div class="winner">?</div>'; var winnerDiv = checkedAppend(html, bracket); vOffset.height(alignTo.position().top - winnerDiv.position().top + alignTo.height() / 2 - winnerDiv.height()); }); function fmtName(name) { return null != name ? name : '?'; } function checkedAppend(rawHtml, appendTo) { var html = $(rawHtml); if (0 == html.length) { throw "Built ourselves bad html : " + rawHtml; } html.appendTo(appendTo); return html; } </script> </head> <body> <div>blah blah blah</div> <div id="writeHere" class="tournament"></div> <div>blah blah blah</div> </body> </html> I tried to do this Code: [Select] <?php function getusername($id){ $sql = mysql_query("SELECT * FROM users WHERE UserID = '".$id."'"); $ROW = mysql_fetch_assoc($sql); $data = $ROW['Username']; return $data; } ?> var matchInfo = { "rounds" : [ { "name": "Round1", "matches" : [ <?php for ($i = 0; $i < $num_rounds; ++$i) { $matches = $teams * pow(.5, $i - 1) / 2; $ROW = mysql_fetch_array($sql); for ($j = 0; $j < $matches; ++$j) { echo '{ "id" : '.$j.', "p1" : "'.$ROW['UserID'].'", "p2" : "'.$ROW['UserID' + $j - 1].'" }'; echo $coma = ','; } echo $coma= ''; }?> but it gives me this Code: [Select] var matchInfo = { "rounds" : [ { "name": "Round1", "matches" : [ { "id" : 0, "p1" : "1", "p2" : "" },{ "id" : 1, "p1" : "1", "p2" : "2" },{ "id" : 2, "p1" : "1", "p2" : "1" },{ "id" : 3, "p1" : "1", "p2" : "1" },{ "id" : 0, "p1" : "15", "p2" : "" },{ "id" : 1, "p1" : "15", "p2" : "3" },{ "id" : 0, "p1" : "17", "p2" : "" }, ] }, according to my database there are 4 teams but with my php script it gives me 7 matches. it should be only 2 matches. cos there are 4 teams. i just cannot figure out this. is there anyone can give me an idea or help me please? thanks I am echoing a variable that is an array. I want to change the first part of the variable but don't know how to manipulte names inside the ['brackets'] Code: [Select] echo $row['v1_name']);?> lets say I have a value called $var = v1. How do I substitute that like this: Code: [Select] echo $row[$var.'_name']);?> I know the above doesnt work, but thats what i want it to do :-) |