Jump to content

paul_mcdonald

New Members
  • Posts

    5
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

paul_mcdonald's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Darn ... I missed the fact that I was already using that $date variable name! Thanks!!!!
  2. I'm doing a conversion of a time between timezones. The conversion part works fine, however when I go to use the $newtime variable as part of my sql statement I get the following error: catchable fatal error : Object of class DateTime could not be converted to string. Here is my code ... any help is appreciated!: // code to handle different timezone $time= $matchtime; $sourceTimezone = new DateTimeZone('America/Halifax'); echo "Halifax :: " .$time; $date = datetime::createFromFormat('H:i', $time, $sourceTimezone); $destinationTimezone = new DateTimeZone('America/St_Johns'); $date->setTimezone($destinationTimezone); $newtime=$date->format('H:i'); echo "<br>StJohns :: ".$newtime; $str = "select * from tbl_schedule where B_id = '$id' and game_date = '$date' and team1_result <> 'Win' and team1_result <> 'Loss' and game_time <= '$newtime'";
  3. For reference .... here is the complete code for the page I'm working with. I don't think the sql sort would work in this case. <?php include_once("admin/header/header.php"); $clsObj=new events(); //$clsobject=new adduser(); $curdate= date("Y-m-d"); $current_events=$clsObj->retrive_curreent_schedule_events($curdate); if(isset($_GET["b_id"])) { $event_details=$clsObj->Retriv_event_name($_GET["b_id"]); $date_s=$event_details['B_startDate']; $year=substr($date_s,0,4); $mon=substr($date_s,5,2); $day=substr($date_s,8,2); $start_date=$mon."/".$day."/".$year; $date_e=$event_details['B_endDate']; $year_e=substr($date_e,0,4); $mon_e=substr($date_e,5,2); $day_e=substr($date_e,8,2); $end_date=$mon_e."/".$day_e."/".$year_e; $club_id=$event_details['B_club_id']; $club_name=$clsObj->Find_clubNameAccordingtievent_id($club_id); $record_all=$clsObj->Retrive_schedule_record_accrodingTOB_ID($_GET["b_id"]); if($record_all>0) { $back_div=""; $same_group=0; $total_teams=array(); $main_counter=0; $counter=0; $youcanwin=array(); $winner_result=array(); $results_data=array(); $result_counter=0; $groups=array(); foreach($record_all as $t=>$main_groups) { $groups[$t]=$record_all[$t]["division"]; } $main_groups=array_count_values($groups); $tot_group =array(); $group_counter=0; foreach($main_groups as $a=>$groups_det) { $tot_group[$group_counter]=$a; $group_counter++; } foreach($record_all as $x=>$value) { $current_div=$record_all[$x]["division"]; if($back_div!=$current_div) { $same_group=1; $main_counter++; } if($main_counter==0) { $total_teams[$main_counter][$counter]=$record_all[$x]["team1_id"]; $youcanwin[$main_counter][$counter]=$record_all[$x]["team1_result"]; $counter++; $total_teams[$main_counter][$counter]=$record_all[$x]["team2_id"]; $youcanwin[$main_counter][$counter]=$record_all[$x]["team2_result"]; $counter++; }else { $total_teams[$main_counter][$counter]=$record_all[$x]["team1_id"]; $youcanwin[$main_counter][$counter]=$record_all[$x]["team1_result"]; $counter++; $total_teams[$main_counter][$counter]=$record_all[$x]["team2_id"]; $youcanwin[$main_counter][$counter]=$record_all[$x]["team2_result"]; $counter++; } $back_div=$record_all[$x]["division"]; } foreach($total_teams as $x=>$value) { $tot_teams=$total_teams[$x]; $tot_result=$youcanwin[$x]; $final_array=array(); foreach($tot_teams as $t => $values) { $key_val=$tot_teams[$t]; $to_res=$tot_result[$t]; if($to_res=="Win") { $win=1; $loss=0; }else if($to_res=="Loss") { $win="0"; $loss="1"; }else { $win="0"; $loss="0"; } if (array_key_exists($key_val,$final_array)) { if($to_res=="Win") { $win=(int)$final_array[$key_val]["Win"] + 1; $loss=(int)$final_array[$key_val]["Loss"] + 0; } if($to_res=="Loss") { $win=(int)$final_array[$key_val]["Win"] + 0 ; $loss=(int)$final_array[$key_val]["Loss"] + 1; } if($to_res=="Not completed") { $win=(int)$final_array[$key_val]["Win"] + 0; $loss=(int)$final_array[$key_val]["Loss"] + 0; } $final_array[$key_val]["Win"]=$win; $final_array[$key_val]["Loss"]=$loss; }else { $final_array[$key_val]["Win"]=$win; $final_array[$key_val]["Loss"]=$loss; } } $results_data[$tot_group[$result_counter]]=$final_array; $result_counter++; } } // print_r($schedule); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?php echo $event_details['B_title'];?> :: Results</title> <link href="css/styles.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="script-css/client.js"></script> </head> <body> <div id="wraper"> <div id="header"> <?php include_once("header_spiel.php"); ?> </div> <div id="body_container"> <div id="page1"> <table width="100%" border="0" class="font12" cellspacing="0" cellpadding="0"> <tr> <td height="40" valign="top"><h2><?php echo $event_details['B_title']; ?> - <?php echo $club_name['club_name']; ?> </h2><?php echo $start_date; ?> - <?php echo $end_date; ?><hr /></td> </tr> <tr> <td style=" padding-top:10px"><h3>Results</h3></td> </tr> <tr> <td height="25"></td> </tr> <tr> <td valign="top"> <table border="0" width="80%" align="left" > <tr> <td align="center">Skip</td> <td align="center">Win</td> <td align="center">Loss</td> </tr> <?php if($results_data>0) { foreach($results_data as $r => $value) { if($r!="") { ?> <tr> <td colspan="3" width="100%" style="background-color:#3333CC; color:#FFFFFF; padding-left:20px;"><?php echo $r; ?></td> </tr> <?php } foreach($results_data[$r] as $z=> $result) { $team_name=$clsObj->Reetrive_team1_Name($z); ?> <tr> <td align="center"><?php echo $z; echo $team_name['team_skipName']; ?></td> <td align="center"><?php echo $results_data[$r][$z]["Win"]; ?></td> <td align="center"><?php echo $results_data[$r][$z]["Loss"]; ?> </td> </tr> <?php } } } else { ?> <tr> <td colspan="2">There have been no results for this event. </td> </tr> <?php }?> </table> </td> </tr> <tr> <td valign="top" class="font12"><p> </p></td> </tr> <tr> <td valign="top"><?php include_once("footer_top.php"); ?></td> </tr> <tr> <td valign="top"> </td> </tr> </table> </div> <?php include_once("footer.php"); ?> </div> </div> </body> </html>
  4. So not possible with current setup? I didn't write the code, just trying to modify to add the sort.
  5. Hello ... I'm fairly new to php. I have some code that calculates wins/losses for teams in a competition. The array contains team number, total wins, total losses. I need to figure out how to sort in order of wins (descending), loss (descending). Here is a sample array contents of $results_data in code below: Array ( [] => Array ( [293] => Array ( [Win] => 6 [Loss] => 0 ) [298] => Array ( [Win] => 6 [Loss] => 3 ) [297] => Array ( [Win] => 3 [Loss] => 3 ) [302] => Array ( [Win] => 2 [Loss] => 3 ) [304] => Array ( [Win] => 5 [Loss] => 3 ) [295] => Array ( [Win] => 6 [Loss] => 3 ) [299] => Array ( [Win] => 2 [Loss] => 3 ) [292] => Array ( [Win] => 1 [Loss] => 3 ) [301] => Array ( [Win] => 3 [Loss] => 3 ) [294] => Array ( [Win] => 4 [Loss] => 3 ) [306] => Array ( [Win] => 2 [Loss] => 3 ) [305] => Array ( [Win] => 1 [Loss] => 3 ) [300] => Array ( [Win] => 1 [Loss] => 3 ) [291] => Array ( [Win] => 3 [Loss] => 3 ) [303] => Array ( [Win] => 0 [Loss] => 3 ) [296] => Array ( [Win] => 0 [Loss] => 3 ) ) ) Here is the code that is used to display the list of teams and results: <?php if($results_data>0) { foreach($results_data as $r => $value) { if($r!="") { ?> <tr> <td colspan="3" width="100%" style="background-color:#3333CC; color:#FFFFFF; padding-left:20px;"><?php echo $r; ?></td> </tr> <?php } foreach($results_data[$r] as $z=> $result) { $team_name=$clsObj->Reetrive_team1_Name($z); ?> <tr> <td align="center"><?php echo $z; echo $team_name['team_skipName']; ?></td> <td align="center"><?php echo $results_data[$r][$z]["Win"]; ?></td> <td align="center"><?php echo $results_data[$r][$z]["Loss"]; ?> </td> </tr> <?php } } } else { ?> <tr> <td colspan="2">There have been no results for this event. </td> </tr> <?php }?> Thank you for your help!
×
×
  • 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.