Jump to content

ultimatemonty

Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ultimatemonty's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. SOLVED! solution was very simple once I cleared my head and tackled it again... [code]function doClassTakenList($classes,$courses) { $i=0; $count = count($classes); do { $class = $classes[$i]; if(array_search($class,$courses)) { $list[$class] = '1'; } else { $list[$class] = '0'; } $i++; } while($i<$count); return($list); }[/code]
  2. I've got two arrays that are being compared in a function. The function is supposed to loop through all the values one array, looking for matches in another array. If it finds a match, it sets an element in the third array to 1. If it finds no matches, it sets the element to 0. Here's the code. [code]function doClassTakenList($classes,$courses) { $i=0; $count = count($classes); do {           $class = $classes[$i]; if(array_search($class,$courses)) { $list[$class][0] = '1'; } else { $list[$class][0] = '0'; } $i++; }         while($i<$count); return($list); } [/code] $classes is a one-dimensional, numerically indexed array containing a list of all classes for a program. IE: [code]$classes = array('SPEC 3110','SPEC3120','SPEC3130','SPEC3140','INTP4010');[/code] $courses is a one-dimensional, numerically indexed array containing a list of classes a student has taken. IE: [code]$courses = array('SPEC 3110','SPEC3180','INTP4010');[/code] $list is an array containing each class and a '1' (for taken) or a '0' (for not taken). instead of returning a numerically indexed, multi-dimensional array (which makes it a real PITA to access the classnames in the $list array), I'd like to build the array something like: [code]if(array_search($class,$courses)) { $list[$class => '1']; } else { $list[$class => '0'] } [/code] this way it's easier to get the class and the associated value. using that particular example, I get a [b]Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting ']'[/b] anyone have any ideas of how to build what I'm needing?
  3. I've been to the AJAXfreaks forums for help, and no one appears to be on there the past few days, so I'm pleading my case here and hoping for something that will get me headed in the right direction... I'm working on a statistics tracking app for my ultimate frisbee team. Each individual stat entry consists of Total Goals, Layout Goals, Sky Goals, Assists, Total Defenses, Layout Ds,  Sky Ds , Total Blocks, Handblocks, Kickblocks. This set of stats is associated with a specific tournamentID, opponentID, and playerID so that we know who did what against which team in which tournament...all this is stored in a MySQL db. I've been able to get AJAX/PHP working so that I can generate a list of tournaments. upon selected the tournament, a list of opponents comes up from that tournament, and upon selected an opponent, a form containg a list players that participated against that opponent shows up. The form code is as follows: snippet from ajax.php [code]function players() {   $tid = $_GET['tid'];   $gid = $_GET['gid'];   print("<form action=\"process.php?mode=stats\" name=\"myform\" method=\"POST\" enctype=\"text/plain\">");   print("<input type=\"hidden\" name=\"tournament\" value=\"" . $tid . "\" />");   print("<input type=\"hidden\" name=\"opponent\" value=\"" . $gid . "\" />");   print("<h3>Input Player Stats</h3>");   print("<table class=\"tracker\" cellspacing=\"0\">");   print("<tr><th>Name</th><th colspan=\"3\">Goals</th><th>Assists</th><th colspan=\"3\">D's</th></tr>");   print("<tr><th class=\"sub\">&nbsp;</th><th class=\"sub\">Total</th><th class=\"sub\">Layout</th><th class=\"sub\">Sky</th><th class=\"sub\">&nbsp;</th><th class=\"sub\">Total</th><th class=\"sub\">Layout</th><th class=\"sub\">Sky</th></tr>");   // Get players from that tournament   $statsQuery = "SELECT playerID FROM stats WHERE tournamentID='$tid' AND gameID='$gid'";   $statsResult = mysql_query($statsQuery) or die('Could not execute query' . mysql_error());   while ($statsRow = mysql_fetch_object($statsResult))   {       $pid = $statsRow->playerID;       $playerQuery = "SELECT * FROM players WHERE playerID = '$pid'";       $playerResults = mysql_query($playerQuery) or die('Could not execute query' . mysqk_error());   //Table Loop with alternating table rows       while($dbRow = mysql_fetch_object($playerResults))       {         if($color==1) {             print("<tr class=\"d0\"");             $color="2";         }         else {         print("<tr class=\"d1\"");         $color="1";         }         print("<td><input type=\"hidden\" name=\"player[$dbRow->playerID]\" value=\"$dbRow->playerID\">$dbRow->full_name</input></td>");         print("<td><input type=\"text\" name=\"tgs[$dbRow->playerID]\" size=\"5\" value=\"0\" /></td>");         print("<td><input type=\"text\" name=\"lgs[$dbRow->playerID]\" size=\"5\" value=\"0\" /></td>");         print("<td><input type=\"text\" name=\"sgs[$dbRow->playerID]\" size=\"5\" value=\"0\" /></td>");         print("<td><input type=\"text\" name=\"assists[$dbRow->playerID]\" size=\"5\" value=\"0\" /></td>");         print("<td><input type=\"text\" name=\"tds[$dbRow->playerID]\" size=\"5\" value=\"0\" /></td>");         print("<td><input type=\"text\" name=\"lds[$dbRow->playerID]\" size=\"5\" value=\"0\" /></td>");         print("<td><input type=\"text\" name=\"sds[$dbRow->playerID]\" size=\"5\" value=\"0\" /></td>");         print("</tr>\n");       }     }     print("</table><hr />");     print("<button name=\"submit\" onClick=\"submitForm();\">Submit</button>");     print("</form>"); } [/code] the javascript running all this is as follows: tracker.js [code]function createRequestObject() {   var req;   if(window.XMLHttpRequest){       // Firefox, Safari, Opera...       req = new XMLHttpRequest();   } else if(window.ActiveXObject) {       // Internet Explorer 5+       req = new ActiveXObject("Microsoft.XMLHTTP");   } else {       // There is an error creating the object,       // just as an old browser is being used.       alert('Problem creating the XMLHttpRequest object');   }   return req; } function handleDivTag(divtag) {   var divtag;   return divtag; } // Make the XMLHttpRequest object var http = createRequestObject(); // Create the Divtag Handler -- Mainly an IE 6 Fix var divhandler = new handleDivTag(null); /* function sendRequest(act,id,divtag) {   // Open PHP script for requests   http.abort;   http.open('post', 'ajax.php', true);   http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');   divhandler.divtag = divtag;   http.send('act='+act); } */ function sendRequest(act,tid,gid,divtag) {   // Open PHP script for requests   http.open('get', 'ajax.php?act='+act+'&tid='+tid+'&gid='+gid);   http.onreadystatechange = handleResponse;   divhandler.divtag = divtag;   http.send(null); } function handleResponse() {   if(http.readyState == 4 && http.status == 200){         // Text returned FROM the PHP script       var response = http.responseText;       if(response) {         // UPDATE ajaxTest content         document.getElementById(divhandler.divtag).innerHTML = response;       }   } } function submitForm() {   form.submit; }[/code] and the action for the form is as follows: process.php [code]<?php include '../db.php'; $mode = $_GET['mode']; if ($mode == "stats") {   addStats(); } else if ($mode == "tournament") {   addTournament(); } else if ($mode == "game") {   addGame(); } else {   echo 'Unauthorized variable passed. Please submit your form again.'; } function addStats() {   foreach($_POST as $key => $item)   {       $key = $_POST[$key];       echo $key . '<br />';   } } ?>[/code] right now I'm just trying to echo the form data that's posted, but I get nothing. The submission does work, as if I just put in an echo 'This text'; statement, I get 'This text' printed on the screen, which tells me that the form data isn't getting sent to process.php.  Any ideas as to why? I've done standard PHP form submission, but I wanted an AJAX approach to make the form more user friendly...if I need to back off of that and go back to just PHP, I will...
  4. ***posted this in PHP General, then realized here was a better place....sorry for the dupe...*** I'm working on a stat tracking application for my ultimate frisbee team. The 'Add Stats' form is generated dynamically based on what tournament you are working on, what game you are adding stats for, and which players attended that tournament.  Each form field has a common name (player, tgs, lgs, sgs, etc etc) followed by the players ID number to identify those stats as belonging to a specific player. so for player ID 3, the form fields would be player_3, tgs_3, sgs_3, etc etc).  There are 8 data fields per player, and there can be upwards of 20 players submitted in a form. Instead of creating individual $_POST('....'] variables for each submitted value (which could be very tedious), is there a way to store the values for each player in a multi-dimensional array, then have the SQL Data Insertion code loop through each value in the array? I haven't done much with arrays in my programming, so I'm not real sure how to work with them. Thanks so much! --Monty
×
×
  • 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.