PHP - Change The Name Of A Variable Inside An Array Bracket
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 :-) Similar TutorialsHi, The array shown below is causing problems. I know this for sure because when I comment the array out the script runs. Is it: 'pswrd1'=>SHA1('$_POST['pswrd1']') inside the array causing the script not to run?? All help will be greatly appreciated. $register_data = array('username'=>$_POST['username'], 'first_name'=>$_POST['first_name'], 'last_name'=>$_POST['last_name'], 'address'=>$_POST['address'], 'postcode'=>$_POST['postcode'], 'country'=>$_POST['country'], 'e_mail'=>$_POST['e_mail'], 'pswrd1'=>SHA1('$_POST['pswrd1']'), 'phone_no'=>$_POST['phone_no']); I tried these below, Code: [Select] class Site extends Controller { function Site() { public $data = Array(); } } but it fail? Thanks in advanced. The Script:
$desired_width = 110; if (isset($_POST['submit'])) { $j = 0; //Variable for indexing uploaded image for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array $target_path = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/uploads/"; //Declaring Path for uploaded images $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) $file_extension = end($ext); //store extensions in the variable $new_image_name = md5(uniqid()) . "." . $ext[count($ext) - 1]; $target_path = $target_path . $new_image_name;//set the target path with a new name of image $j = $j + 1;//increment the number of uploaded images according to the files in array if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded. && in_array($file_extension, $validextensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>'; $tqs = "INSERT INTO images (`original_image_name`, `image_file`, `date_created`) VALUES ('" . $_FILES['file']['name'][$i] . "', '" . $new_image_name . "', now())"; $tqr = mysqli_query($dbc, $tqs); // Select the ID numbers of the last inserted images and store them inside an array. // Use the implode() function on the array to have a string of the ID numbers separated by commas. // Store the ID numbers in the "image_file_id" column of the "thread" table. $tqs = "SELECT `id` FROM `images` WHERE `image_file` IN ('$new_image_name')"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $fetch_array = array(); $row = mysqli_fetch_array($tqr); $fetch_array[] = $row['id']; /* * This prints e.g.: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 ) */ print_r($fetch_array); // Goes over to create the thumbnail images. $src = $target_path; $dest = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/thumbs/" . $new_image_name; make_thumb($src, $dest, $desired_width); } else {//if file was not moved. echo $j. ').<span id="error">please try again!.</span><br/><br/>'; } } else {//if file size and file type was incorrect. echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>'; } } }Hey, sorry that I am posting this darn image upload script again, I have this almost finished and I am not looking to ask more questions when it comes to this script specifically. With the script above I have that part where the script should store the ID numbers (the auto_increment column of the table) of the image files inside of one array and then the "implode()" function would get used on the array and then the ID numbers would get inserted into the "image_file_id" column of the "thread" table. As you can see at the above part the script prints the following: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 )And I am looking to insert into the column of the table the following: 542, 543, 544I thought of re-writing the whole image upload script since this happens inside the for loop, though I thought maybe I could be having this done with the script as it is right now. Any suggestions on how to do this? I am trying to allow the user to update a variable he chooses by radio buttons, which they will then input text into a box, and submit, to change some attributes. I really need some help here. It works just fine until I add the second layer of variables on top of it, and I can't find the answer to this question anywhere. <?PHP require('connect.php'); ?> <form action ='' method='post'> <select name="id"> <?php $extract = mysql_query("SELECT * FROM cars"); while($row=mysql_fetch_assoc($extract)){ $id = $row['id']; $make= $row['make']; $model= $row['model']; $year= $row['year']; $color= $row['color']; echo "<option value=$id>$color $year $make $model</option> ";}?> </select> Which attribute would you like to change?<br /> <input type="radio" name="getchanged" value="make"/>Make<br /> <input type="radio" name="getchanged" value="model"/>Model<br /> <input type="radio" name="getchanged" value="year" />Year<br /> <input type="radio" name="getchanged" value="color" />Color<br /><br /> <br /><input type='text' value='' name='tochange'> <input type='submit' value='Change' name='submit'> </form> //This is where I need help... <?PHP if(isset($_POST['submit'])&&($_POST['tochange'])){ mysql_query(" UPDATE cars SET '$_POST[getchanged]'='$_POST[tochange]' where id = '$_POST[id]' ");}?> 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; } I dont know why I'm having so many problems with this. I need to get a variable that defined in an included file inside of a function I've got this Inside file.php I've got the $variable1 and $variable2 defined (they're dynamic/different to each user) include('file.php'); function foo() { GLOBAL $variable1, $variable2; echo $variable1; echo $variable2; } foo(); Yet it outputs nothing? If I Include file.php right inside of the function it works however. Any idea? i have a variable called $cake it needs to have this loop inside it so I can call it out Code: [Select] while( $r = $DB->fetch_row() ){ if ( $r['last_activity'] > (time() - 900) ) $r['status'] = "<span style=float:right;><span class=desc4><b>Online</b></span></span>"; else $r['status'] = "<span style=float:right;><span class=desc4>Offline</span></span>"; $column++; if ($ibforums->member['settings']['2'] or (!$ibforums->member['id'])){ $color = "{$r['color']}"; $colors = explode(",", $color); if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ){ { $r['color'] = ($r['color']) ? "style=\"padding:1px 1px 1px 2px;color:#{$colors[0]};filter:Glow(color=#{$colors[1]},strength=3)\"":""; } }else{ $r['color'] = ($r['color']) ? "style=\"color:#{$colors[0]};text-shadow:#{$colors[1]} 2px 1px 1px\"":""; } } $test = explode(";", $info['pdata']); $r['avatar'] = ($r['avatar']) ? "<img src={$r['avatar']} width=64 height=64>" : ""; $r['star'] = ($r['star']) ? "<img class=top3 src=style_images/1/icons/{$r['star']}.png>":""; $r['name'] = "<a href=?i={$r['friendid']}>{$r['name']}{$r['star']}</a>"; $this->to_print .= <<< LOL <dl class="LOL LEFT flm" style="margin-right:5px"><dt2>{$r['name']}</dt2><dd class=padding4>{$r['avatar']}<div class="RIGHT">{$r['status']}</div></dd></dl> LOL; } I tried: Code: [Select] $cake = ' while( $r = $DB->fetch_row() ){ if ( $r['last_activity'] > (time() - 900) ) $r['status'] = "<span style=float:right;><span class=desc4><b>Online</b></span></span>"; else $r['status'] = "<span style=float:right;><span class=desc4>Offline</span></span>"; $column++; if ($ibforums->member['settings']['2'] or (!$ibforums->member['id'])){ $color = "{$r['color']}"; $colors = explode(",", $color); if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ){ { $r['color'] = ($r['color']) ? "style=\"padding:1px 1px 1px 2px;color:#{$colors[0]};filter:Glow(color=#{$colors[1]},strength=3)\"":""; } }else{ $r['color'] = ($r['color']) ? "style=\"color:#{$colors[0]};text-shadow:#{$colors[1]} 2px 1px 1px\"":""; } } $test = explode(";", $info['pdata']); $r['avatar'] = ($r['avatar']) ? "<img src={$r['avatar']} width=64 height=64>" : ""; $r['star'] = ($r['star']) ? "<img class=top3 src=style_images/1/icons/{$r['star']}.png>":""; $r['name'] = "<a href=?i={$r['friendid']}>{$r['name']}{$r['star']}</a>"; $this->to_print .= <<< LOL <dl class="LOL LEFT flm" style="margin-right:5px"><dt2>{$r['name']}</dt2><dd class=padding4>{$r['avatar']}<div class="RIGHT">{$r['status']}</div></dd></dl> LOL; }'; but not working Im having a problem with getting the quotes correct with this. I can either get the variable to work in the href and img src or in the css. Anyone have any ideas on this. Cuase im really stuck. This allows the $address and $cos to echo in but not the css variables <td><?php echo "<a href='planet_profile.php?planet=$address'> <img src='images/star.jpg' id='$cos' style='position:absolute;' left:'$b_x px;' top:'$b_y px;'></a>"; ?></td> and this allows only the css variables to work <td><?php echo '<a href="planet_profile.php?planet="' . $address . '"> <img src="images/star.jpg" id="' . $cos . '" style="position:absolute; left:' . $b_x . 'px; top:' . $b_y . 'px;"></a>'; ?></td> If I have a for loop with a variable called $counter, how can I use the value of this inside a variable name. For example: If I want a bunch of variables called $d1name, $d2name, $d3name ...etc. what's the correct syntax to use? The following gives me a string but not a variable name: $myVariable = "$"."d".$counter."name"; 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> <? } ?> I'm trying to build a math game. But I'm having trouble trying to make a variable calculate that contains an operator. Example: $c1_op = "+"; $a1_num_user = $_POST['a1_num']; $e1_num_user = $_POST['e3_num']; $row_1 = $a1_num_user . $c1_op . $e1_num_user; echo "result: " . $row_1; If I now input a 10 and a 2 I will get echo'd out: result: 10+2 It's not calculating. When I don't use any quotation marks then I will get the error "unexpected ;". I need the operator inside a variable, it's the nature of the math game, any idea how I can make it work so it calculates? The org variable holds the value of the folder name. The problem is that the header is sending out ".$org." and not the actual value of $org. Example output url: http://127.0.0.1/application/".$org."/display/trackingboard.php I want this url if the value is test: http://127.0.0.1/application/test/display/trackingboard.php Thanks! Code: [Select] $org = "test"; header('Location: ../application/".$org."/display/trackingboard.php'); I'm redoing my login script using functions and a basic switch function checking against a $_GET variable (hope you guys know what I'm talking about). What I want to do is create two functions: 1 that displays the login form and 1 that processes the information The form tag would look like this: <form action=\"<?php $_SERVER['PHP_SELF']?>?action=process\" method=\"post\"> </form> Here's my switch statement: Code: [Select] <?php //**************************************** //****************Action****************** //**************************************** switch ($_GET["action"]) { default: case "index": if (!$_SESSION["member"]) { if (!$timeout) { display_form(); } else { echo $timeout_error; } } else { echo "You are already logged in."; } break; case "process": if (!$_SESSION["member"]) { if (!$timeout) { process_form(); } else { echo $timeout_error; } } else { echo "You are already logged in."; } break; } ?> This runs as soon as "login.php" loads. It'll automatically run the commands under case "default" and "index". It'll first check to see if the member's logged in. If not, it'll then check to see if "$timeout" is true ($timeout becomes true if the member has attempted to login 5 times and failed). If not, it'll display the login form, by running "display_form()". Once the form has been filled and submitted, the commands under case "process" will be performed. Again it will first check to see if the member's logged in. If not, it'll check to see if "$timeout" is true. If not, it'll start validating the forms. For the validation, I've created a variable called "$errors_found", and scripted one if statement checking to see if the email and password exist. If so, the variables "$rm_field_un" and "$rm_field_pw" become true, as well as "$errors_found". So, back to submission of the form... If "$errors_found" is true, display the form (when the form is displayed, there will be an if statement within that says "<?php if ($rm_field_un) { echo "Username is wrong."; } ?>", which will be displayed right underneath the username field and label. Same with the password elements). If "$errors_found" is not true, go ahead and register the member. Now, here's where I need help, because I'm really confused as to how to accomplish this. The "display_form()" function will contain a single variable called "$login_form". It will contain a value of the HTML constructed login form, and the function will return the variable. Remember how I stated in the third paragraph up that I will have <php> statements within the form which would display errors if necessary? Well, how do I put those if statements within the HTML, which is contained within the variable? If that last question confuses you, allow me to present you with an instance: Code: [Select] <?php function display_form() { $login_form = " <form name=\"login_form\" method=\"post\" action=\"<?php $_SERVER['PHP_SELF']?>?action=process\"> Username: <input type=\"text\"> <?php if ($rm_field_un) { echo "Username is wrong"; } ?> "; return $login_form; } ?> See what I mean? This code confuses me ALOT. I'm not sure if the <php> tags are needed as it is already contained within existing ones, or what. Can somebody please help me out? Any and all help is much appreciated. =D Hi Everyone, I have built a website utilizing a PHP abstract Webpage class to create the pages. When creating another class that inherits from Webpage class I rewrite abstract functions, etc. where needed. When instantiating an object of the extended classes I pass the constructor the $page_title, $css_file, $meta_data, $keywords, etc., etc.. I am able to pass html markup in a string variable to a class level "Setter" function to populate a "main area" of the website and all works perfectly. However, I have a contact form which I send the "Submit Message" button click to a PHP function that takes care of making sure the form fields are not empty, then sends email and returns a success message back to the calling page, if they are empty, the function returns what fields are empty(required). If the page includes empty and populated fields I want to put the populated fields into session variables so that I may populate the fields when the user is taken back to the page and display to the user the required fields that were empty(this functionality is already within the function). This brings me to my question(see code below for reference): Seeing that I am populating a variable with a string it seems I cannot use an if statement, echo or the like, my IDE gives me errors. How may I insert an if statement where needed to populate the empty form fields? Code: [Select] include('../php_functions/functions.php');//for the chechData() function $error_message = NULL; if(isset($_POST['submit'])) { $error_message = checkData($_POST, 'Renovation & Consulting'); } $main_content = '<form method="post" action=""> <fieldset id="contactform"> <legend>Renovations & Consultations</legend>'. [color=red]//placing a variable here works fine![/color] $error_message .'<div class="row_div"> <div class="label_div"> <label>First Name:</label> </div> <div class="input_div"> <input name="First Name" type="text" maxlength="50" size="50" value="'.[color=red]if(session variable not empty) echo it here;.'"[/color] /> </div> </div> <div class="row_div"> <input name="submit" type="submit" value="Send Message" /> </div> </fieldset> </form>'; Thanks for any and all responses. Chuck how can you increase the page number in the following line until $status returns an empty result? curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization: xxxxxxxxxxxxx:xxxxxxxxxxxxxxxx", "Page: 2")); Hi guys im in the middle of optimizing code.. Code: [Select] $sql = "SELECT * FROM sa_enemystats WHERE username='$username'"; $res = mysql_query($sql); while ($row = mysql_fetch_assoc($res)) { $enemy['current_health'] = $row['current_health']; $enemy['current_skill'] = $row['current_skill']; $enemy['level'] = $row['level']; $enemy['damage'] = $row['damage']; $enemy['evade'] = $row['evade']; $enemy['accuracy'] = $row['accuracy']; $enemy['speed'] = $row['speed']; $enemy['luck'] = $row['luck']; echo 'debug: variables synced with db table'; }I know that the setting of these variables are messy and can be done in a better way... but how? I have tried foreach and copying other's code for an array copy but it lead no where. Then again my syntax could be wrong... I used something like Code: [Select] foreach ( $enemy[$value] as $row => $value) { $enemy[$value] = $row[$value]; } 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 Trying to figure out how to make it so name is a link to the profile when its echo anyone know how to do this? im at a huge stand still Code: [Select] <?php $sql = "SELECT name FROM users WHERE DATE_SUB(NOW(),INTERVAL 5 MINUTE) <= lastactive ORDER BY id ASC"; $query = mysql_query($sql) or die(mysql_error()); $count = mysql_num_rows($query); $i = 1; while($row = mysql_fetch_object($query)) { $online_name = htmlspecialchars($row->name); echo '<a href="Inbox.php">"'[$goauld]'</a>"'; ?> I need a help in the following : I have an admin page from where the admin attaches an gif image.This attached image should be shown to the user as a scrolling image. The code for the scrolling image is done through javascript. So my actual problem is getting the name of the attached gif image to the javascript array which is used for scrolling horizontally. |