Solved

I need an sql statement

Posted on 2008-10-13
9
319 Views
Last Modified: 2013-12-13
I have a script on my server that is not executing at all. It works perfectly on my local machine but not on the server. both systems have PHP5 installed and all the other pages work fine except this one.

I am concerned that it may be a difference in the php.ini files that will not allow mass deletes etc. on the server.

Any ideas would be most welcome!
<?php
//BindEvents Method @1-D40060DD
function BindEvents()
{
    global $CCSEvents;
    $CCSEvents["BeforeShow"] = "Page_BeforeShow";
}
//End BindEvents Method
 
//Page_BeforeShow @1-8458E52C
function Page_BeforeShow(& $sender)
{
    $Page_BeforeShow = true;
    $Component = & $sender;
    $Container = & CCGetParentContainer($sender);
    global $calculation; //Compatibility
//End Page_BeforeShow
 
//Custom Code @60-2A29BDB7
// -------------------------
    // Write your own code here.
 
//Start all calculations *********************************************************************
global $sel_cat;
global $weight;
global $sel_ins_cat;
global $pos_tot;
global $mod_check;
 
  $db = new clsDBhockey_stats();
 
//Delete all records in the report:
$sql= "DELETE from report where user_id = ".CCGetUserID();
$db->query($sql);
 
//Get the stat_categories that the user has selected
	$sql="SELECT lu_stat_categories.category, category_weights.weight FROM category_weights LEFT JOIN lu_stat_categories ON category_weights.stat_category_id = lu_stat_categories.ID
	WHERE category_weights.yes_no=1 AND category_weights.user_id=".CCGetUserID();
	$db->query($sql);
 
//Create an array of the user selected categories
  while($db->next_record())
{
	$sel_cat[]=$db->f("category");//store all cats in an array
	$weight[]=$db->f("weight");//Store the weights for the calcs
}
 
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){
   switch ($sel_cat[$i]) {
case "g":
    $sel_ins_cat=$sel_cat[$i].",";
	break;
case "a":
	$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "p":
	$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "plus_minus":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "pim":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "ppg":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "ppa":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "ppp":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "shg":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "sha":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "shp":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "sog":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "shot_perc":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "gwg":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "fw":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "hits":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "atoi":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
case "f_perc":
    $sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
    break;
	$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
}
}
$sel_ins_cat = rtrim($sel_ins_cat,",");//Remove the last comma
 
//Routine Complete *********************************************************************
 
//Get the positions and total number for each position from league_info
  $sql= "select * from league_info where user_id = ".CCGetUserID();
  $db->query($sql);
  while($db->next_record())
{
$pos_tot[]=$db->f("position")."|".$db->f("total_owned");//store all positions and tot number for each pos in an array
$position[]=$db->f("position");//Store the positions only for later calcs/
 
}
 
//Routine Complete *********************************************************************
 
//Get the annex for the specific group of stats that the user has chosen to complete the View name.
$sql= "select stats_used from league_setup WHERE user_id = ".CCGetUserID();
$db->query($sql);
$Result = $db->next_record();
$annex_used = $db->f("stats_used");
 
//Break down annex used to see if user-defined cats are being used i.e any _mod views
$mod_check = strrev($annex_used);
if (substr($mod_check,0,3) == "dom") {
$mod_check = true;}
else{
$mod_check = false;
}
 
//Start  the insertion of data into the c_selected_players table.
for ($i=0;$i<=(sizeof($pos_tot)-1);$i++)
{
   $pos1 = substr($pos_tot[$i],0,stripos($pos_tot[$i],"|"));//Extract the position from the string
   $tot1 = substr($pos_tot[$i],stripos($pos_tot[$i],"|")+1);//Extract the tot number from the string
 
   switch ($pos1) {
case 1://C
if ($mod_check == 1) {
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_c".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;	
	}
else
{
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_c".$annex_used." LIMIT 0,".$tot1;
}
	$db->query($sql);
 
	break;
case 2://LW
if ($mod_check == 1) {
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_lw".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;	
	}
else
{
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_lw".$annex_used." LIMIT 0,".$tot1;
}
	$db->query($sql);
	break;
case 3://RW
if ($mod_check == 1) {
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_rw".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;	
	}
else
{
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_rw".$annex_used." LIMIT 0,".$tot1;
}	
	$db->query($sql);
		break;
case 4://F
if ($mod_check == 1) {
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_f".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;
	}
else
{
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_f".$annex_used." LIMIT 0,".$tot1;
}
	$db->query($sql);
//Update all the positions to 4.
$sql = "UPDATE c_selected_players SET c_selected_players.position_id = 4 where position_id IN (1,2,3)";
$db->query($sql);
	break;
case 5://W
if ($mod_check == 1) {
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_w".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;	
	}
else
{
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_w".$annex_used." LIMIT 0,".$tot1;
}
	$db->query($sql);
//Update all the positions to 5.
$sql = "UPDATE c_selected_players SET c_selected_players.position_id = 4 where position_id IN (2,3)";
$db->query($sql);
	break;
case 6://D
if ($mod_check == 1) {
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_d".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;	
	}
else 
{
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_d".$annex_used." LIMIT 0,".$tot1;
}
	$db->query($sql);
	break;
case 7://Bench
if ($mod_check == 1) {
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_b".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;	
	}
else
{
	$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
	SELECT player_id, position_id,".$sel_ins_cat." FROM 1_b".$annex_used." LIMIT 0,".$tot1;
}
	$db->query($sql);
	break;
}
}
//Add user_id to the new records where it is NULL.
//Set the user_id
$sql = "UPDATE c_selected_players SET c_selected_players.user_id = " .CCGetUserID()." where user_id IS NULL";
$db->query($sql);
 
//Routine Complete *********************************************************************
 
//Create the average and Standard deviation for each position for each category the user has chosen
for ($i=0;$i<=(sizeof($position)-1);$i++)
{
   switch ($position[$i]) {
case 1://C
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 1 group by position_id";
	$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 1 group by position_id";
	$db->query($sql);
break;
case 2://LW
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 2 group by position_id";
	$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 2 group by position_id";
	$db->query($sql);
	break;
case 3://RW
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 3 group by position_id";
	$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 3 group by position_id";
	$db->query($sql);
	break;
case 6://D
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 6 group by position_id";
	$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 6 group by position_id";
	$db->query($sql);
	break;
case 7://Bench
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 7 group by position_id";
	$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 7 group by position_id";
	$db->query($sql);
	break;
case 4://F
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 4 group by user_id";
	$db->query($sql);
//Update the position ID
$sql = "UPDATE c_avg_at_pos SET c_avg_at_pos.position_id = 4 where position_id IS NULL";
$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 4 group by user_id";
	$db->query($sql);
//Update the position ID
$sql = "UPDATE c_std_deviation SET c_std_deviation.position_id = 4 where position_id IS NULL";
$db->query($sql);
	break;
case 5://W
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 5 group by user_id";
	$db->query($sql);
//Update the position ID
$sql = "UPDATE c_avg_at_pos SET c_avg_at_pos.position_id = 5 where position_id IS NULL";
$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 5 group by user_id";
	$db->query($sql);
//Update the position ID
$sql = "UPDATE c_std_deviation SET c_std_deviation.position_id = 5 where position_id IS NULL";
$db->query($sql);
 
}
}
//Routine Complete *********************************************************************
//Do the actual calculations.
global $avg;
global $std;
global $j;
global $player_stat;
 
//Start the main loop for Calculations +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$db1 = new clsDBhockey_stats();
 
//Copy Base data from c_selected_players into the c_values table.
 $sql= "INSERT INTO c_values ( user_id, player_id, position_id) SELECT user_id, player_id, position_id FROM c_selected_players where user_id = ".CCGetUserID();
  $db->query($sql);
 
//No start updating tha data in c_values with the calculation results.
  $sql= "select * from c_selected_players where user_id = ".CCGetUserID();
  $db->query($sql);
 
  while($db->next_record())
  {
 
for ($j=0;$j<=(sizeof($position)-1);$j++){
   switch ($position[$j]) {
case 1://C
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 1";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 1";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 1";
  $db1->query($sql);
  }
}
	break;
case 2://LW
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 2";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 2";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 2";
  $db1->query($sql);
  }
}
	break;
case 3://RW
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 3";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 3";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 3";
  $db1->query($sql);
  }
}
	break;
case 4://C,LW,RW
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 4";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 4";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 4";
  $db1->query($sql);
  }
}
	break;
case 5://Lw,RW
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 5";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 5";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 5";
  $db1->query($sql);
  }
}
	break;
case 6://D
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 6";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 6";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 6";
  $db1->query($sql);
  }
}
	break;
case 7://Bench
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 7";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 7";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 7";
  $db1->query($sql);
  }
}
	break;
}//Position
}//loop through categories
}//Loop through c_values
 
//Calculate the total_value field by removing all NULLS as sql returns NULL if any NULL in columns.
global $cols;
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){
$cols = $cols."+".$sel_cat[$i];
$cols = ltrim($cols,"+");//Remove the first +
}
 
  $sql= "select * from c_values where user_id = ".CCGetUserID();
  $db->query($sql);
  while($db->next_record())
  {
$sql= "UPDATE c_values SET total_value = ".$cols;
  $db1->query($sql);
}
//Routine Complete *********************************************************************
 //Save the results
$sql= "INSERT into report (user_id, player_id, position_id, value_calc) SELECT user_id, player_id, position_id, total_value from c_values WHERE user_id = ".CCGetUserID();
$db->query($sql);
 
 //Clean up all the tables:
$sql= "DELETE from c_selected_players where user_id = ".CCGetUserID();
$db->query($sql);
$sql= "DELETE from c_std_deviation where user_id = ".CCGetUserID();
$db->query($sql);
$sql= "DELETE from c_avg_at_pos where user_id = ".CCGetUserID();
$db->query($sql);
$sql= "DELETE from c_values where user_id = ".CCGetUserID();
$db->query($sql);
 
 
//Close the connection.
  $db->close();
  $db1->close();
// -------------------------
 
global  $Redirect;
 
  $Redirect = "calculation_results.php";
 
//End Custom Code
 
//Close Page_BeforeShow @1-4BC230CD
    return $Page_BeforeShow;
}
//End Close Page_BeforeShow
 
 
?>

Open in new window

0
Comment
Question by:theseowgroup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
9 Comments
 
LVL 8

Expert Comment

by:nahime
ID: 22706785
Are you sure that the connection at the db on the server works?
0
 

Author Comment

by:theseowgroup
ID: 22706847
Yes! All the other scripts are working perfectly. They include inserts, updates, selects etc.
0
 
LVL 8

Expert Comment

by:nahime
ID: 22706871
mmm, I really don't know what could be.
0
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 

Author Comment

by:theseowgroup
ID: 22706955
Yup, That is the problem! I cannot fogure out why the php.ini could make a diffence.
Anyway, thanks for the reply.
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22730633
Can you confirm that this line is successful once it's on the server?

$db = new clsDBhockey_stats();
0
 

Author Comment

by:theseowgroup
ID: 22732440
Yes, the line is successful. I am thinking that when I uploaded my sql script to the server (apache, mysql) the views were not created successfully. Does anyone know a free utility that will export Mysql databases to a file and have all tables, data and views correct. I used MySQL Administrator and when I try to run a select query on a view, I get an empty rowset returned and yet I know that there is data there.

Thanks,

Trevor
0
 
LVL 6

Expert Comment

by:James Looney
ID: 22732467
I've always used phpMyAdmin (web-based). It is super nice, and robust.

http://www.phpmyadmin.net/home_page/index.php

0
 

Author Comment

by:theseowgroup
ID: 22732573
I will give that a try. Thanks.
0
 

Accepted Solution

by:
theseowgroup earned 0 total points
ID: 22735794
Well, the problm has been solved. When uploading the sql to the server, all the views appeared to have been updated correctly but they were not! I ended up creating the views manually on the server and all works correctly now.

No real solution but thank you all for your responses.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question