Comments on: Conditions on Count or Sum in MySQL http://codespatter.com/2008/07/22/conditions-on-count-or-sum-in-mysql/ Wed, 13 Mar 2013 20:51:33 +0000 http://wordpress.org/?v=2.8.4 hourly 1 By: vai http://codespatter.com/2008/07/22/conditions-on-count-or-sum-in-mysql/comment-page-1/#comment-15298 vai Fri, 07 May 2010 23:47:23 +0000 http://codespatter.com/?p=42#comment-15298 <p>hai, i need help in points calculation in php.</p> <p>i did the points calculation already. but dont know to input it in the database? can anyone help me out?</p> <p>$sql ="select * from tbl_predictions where user_id=".$user_id;<br>$result =$db->readValues($sql);<br>$prediction_points = 0;</p> <p>for($k=0;$kreadValues($sql);</p> <p>$week_points = 0;<br>if(count($predictions)>0){</p> <p>for($p=0;$preadValues("select * from tbl_schedule where id_schedule=".$predictions[$p]['match_id']);<br>$scorer_team1 = explode('^^^',$predictions[$p]['scorer1']);<br>$scorer_team2 = explode('^^^',$predictions[$p]['scorer2']);</p> <p>$sql = ("select result from tbl_schedule where period='$week' and id_schedule=".$predictions[$p]['match_id']);<br>$InsertedR = $db->readValues($sql);</p> <p>$points = 0;</p> <p>if($predictions[$p]['result']==$teams[0]['result']){</p> <p>$points = $points+2;</p> <p>}</p> <p>if($predictions[$p]['scoreline1']==$teams[0]['team1_scoreline'] && $predictions[$p]['scoreline2']==$teams[0]['team2_scoreline']){</p> <p>$points = $points+2;</p> <p>}</p> <p>if($predictions[$p]['goal1']==$teams[0]['team1_goals'] && $predictions[$p]['goal2']==$teams[0]['team2_goals']){</p> <p>$points = $points+2;</p> <p>}<br>if($predictions[$p]['redcard1']==$teams[0]['team1_cards'] && $predictions[$p]['redcard2']==$teams[0]['team2_cards']){</p> <p>$points = $points+2;</p> <p>}</p> <p>$scorer1 = array();<br>$scorer2 = array();<br>$scorer3 = array();<br>$scorer4 = array();</p> <p>$scorer1 = explode('^^^',$teams[0]['team1_scorer']);<br>$scorer2 = explode('^^^',$teams[0]['team2_scorer']);<br>$scorer3 = explode('^^^',$predictions[$p]['scorer1']);<br>$scorer4 = explode('^^^',$predictions[$p]['scorer2']);</p> <p>$available = array_diff_assoc($scorer1, $scorer3);</p> <p>#print_r($available);</p> <p>$available1 = array_diff_assoc($scorer2, $scorer4);</p> <p>#print_r($available1);</p> <p>if(count($available)>0&&count($available1)>0){<br>$points = $points+2;<br>}</p> <p>if ($InsertedR[0]['result'] == 0){</p> <p>$points = 0;<br>}else{<br>$points = $points;</p> <p>}</p> <p>}</p> <p>//echo $week.'==='.$week_points;<br>$week_points = $week_points+$points;</p> <p>}</p> <p>$prediction_points =$week_points+$prediction_points ;</p> <p>// echo $total_points.'=====';</p> <p>}</p> <p>?></p> <p>How input the week_points into database now, since i have created column in mysql weekPoints. the data will be insert based on user_id per user. how to do it?</p> hai, i need help in points calculation in php.

i did the points calculation already. but dont know to input it in the database? can anyone help me out?

$sql =”select * from tbl_predictions where user_id=”.$user_id;
$result =$db->readValues($sql);
$prediction_points = 0;

for($k=0;$kreadValues($sql);

$week_points = 0;
if(count($predictions)>0){

for($p=0;$preadValues(”select * from tbl_schedule where id_schedule=”.$predictions[$p]['match_id']);
$scorer_team1 = explode('^^^',$predictions[$p]['scorer1']);
$scorer_team2 = explode('^^^',$predictions[$p]['scorer2']);

$sql = (”select result from tbl_schedule where period='$week' and id_schedule=”.$predictions[$p]['match_id']);
$InsertedR = $db->readValues($sql);

$points = 0;

if($predictions[$p]['result']==$teams[0]['result']){

$points = $points+2;

}

if($predictions[$p]['scoreline1']==$teams[0]['team1_scoreline'] && $predictions[$p]['scoreline2']==$teams[0]['team2_scoreline']){

$points = $points+2;

}

if($predictions[$p]['goal1']==$teams[0]['team1_goals'] && $predictions[$p]['goal2']==$teams[0]['team2_goals']){

$points = $points+2;

}
if($predictions[$p]['redcard1']==$teams[0]['team1_cards'] && $predictions[$p]['redcard2']==$teams[0]['team2_cards']){

$points = $points+2;

}

$scorer1 = array();
$scorer2 = array();
$scorer3 = array();
$scorer4 = array();

$scorer1 = explode('^^^',$teams[0]['team1_scorer']);
$scorer2 = explode('^^^',$teams[0]['team2_scorer']);
$scorer3 = explode('^^^',$predictions[$p]['scorer1']);
$scorer4 = explode('^^^',$predictions[$p]['scorer2']);

$available = array_diff_assoc($scorer1, $scorer3);

#print_r($available);

$available1 = array_diff_assoc($scorer2, $scorer4);

#print_r($available1);

if(count($available)>0&&count($available1)>0){
$points = $points+2;
}

if ($InsertedR[0]['result'] == 0){

$points = 0;
}else{
$points = $points;

}

}

//echo $week.'==='.$week_points;
$week_points = $week_points+$points;

}

$prediction_points =$week_points+$prediction_points ;

// echo $total_points.'=====';

}

?>

How input the week_points into database now, since i have created column in mysql weekPoints. the data will be insert based on user_id per user. how to do it?

]]>
By: vai http://codespatter.com/2008/07/22/conditions-on-count-or-sum-in-mysql/comment-page-1/#comment-15227 vai Fri, 07 May 2010 18:47:23 +0000 http://codespatter.com/?p=42#comment-15227 hai, i need help in points calculation in php.<br><br>i did the points calculation already. but dont know to input it in the database? can anyone help me out?<br><br>$sql ="select * from tbl_predictions where user_id=".$user_id;<br>$result =$db->readValues($sql);<br>$prediction_points = 0;<br><br>for($k=0;$kreadValues($sql);<br><br>$week_points = 0;<br>if(count($predictions)>0){<br><br>for($p=0;$preadValues("select * from tbl_schedule where id_schedule=".$predictions[$p]['match_id']);<br>$scorer_team1 = explode('^^^',$predictions[$p]['scorer1']);<br>$scorer_team2 = explode('^^^',$predictions[$p]['scorer2']);<br><br>$sql = ("select result from tbl_schedule where period='$week' and id_schedule=".$predictions[$p]['match_id']);<br>$InsertedR = $db->readValues($sql);<br><br>$points = 0;<br><br>if($predictions[$p]['result']==$teams[0]['result']){<br><br>$points = $points+2;<br><br>}<br><br>if($predictions[$p]['scoreline1']==$teams[0]['team1_scoreline'] && $predictions[$p]['scoreline2']==$teams[0]['team2_scoreline']){<br><br>$points = $points+2;<br><br>}<br><br>if($predictions[$p]['goal1']==$teams[0]['team1_goals'] && $predictions[$p]['goal2']==$teams[0]['team2_goals']){<br><br>$points = $points+2;<br><br>}<br>if($predictions[$p]['redcard1']==$teams[0]['team1_cards'] && $predictions[$p]['redcard2']==$teams[0]['team2_cards']){<br><br>$points = $points+2;<br><br>}<br><br>$scorer1 = array();<br>$scorer2 = array();<br>$scorer3 = array();<br>$scorer4 = array();<br><br>$scorer1 = explode('^^^',$teams[0]['team1_scorer']);<br>$scorer2 = explode('^^^',$teams[0]['team2_scorer']);<br>$scorer3 = explode('^^^',$predictions[$p]['scorer1']);<br>$scorer4 = explode('^^^',$predictions[$p]['scorer2']);<br><br>$available = array_diff_assoc($scorer1, $scorer3);<br><br>#print_r($available);<br><br>$available1 = array_diff_assoc($scorer2, $scorer4);<br><br>#print_r($available1);<br><br>if(count($available)>0&&count($available1)>0){<br>$points = $points+2;<br>}<br><br>if ($InsertedR[0]['result'] == 0){<br><br>$points = 0;<br>}else{<br>$points = $points;<br><br>}<br><br>}<br><br>//echo $week.'==='.$week_points;<br>$week_points = $week_points+$points;<br><br>}<br><br>$prediction_points =$week_points+$prediction_points ;<br><br>// echo $total_points.'=====';<br><br>}<br><br>?><br><br>How input the week_points into database now, since i have created column in mysql weekPoints. the data will be insert based on user_id per user. how to do it? hai, i need help in points calculation in php.

i did the points calculation already. but dont know to input it in the database? can anyone help me out?

$sql =”select * from tbl_predictions where user_id=”.$user_id;
$result =$db->readValues($sql);
$prediction_points = 0;

for($k=0;$kreadValues($sql);

$week_points = 0;
if(count($predictions)>0){

for($p=0;$preadValues(”select * from tbl_schedule where id_schedule=”.$predictions[$p]['match_id']);
$scorer_team1 = explode('^^^',$predictions[$p]['scorer1']);
$scorer_team2 = explode('^^^',$predictions[$p]['scorer2']);

$sql = (”select result from tbl_schedule where period='$week' and id_schedule=”.$predictions[$p]['match_id']);
$InsertedR = $db->readValues($sql);

$points = 0;

if($predictions[$p]['result']==$teams[0]['result']){

$points = $points+2;

}

if($predictions[$p]['scoreline1']==$teams[0]['team1_scoreline'] && $predictions[$p]['scoreline2']==$teams[0]['team2_scoreline']){

$points = $points+2;

}

if($predictions[$p]['goal1']==$teams[0]['team1_goals'] && $predictions[$p]['goal2']==$teams[0]['team2_goals']){

$points = $points+2;

}
if($predictions[$p]['redcard1']==$teams[0]['team1_cards'] && $predictions[$p]['redcard2']==$teams[0]['team2_cards']){

$points = $points+2;

}

$scorer1 = array();
$scorer2 = array();
$scorer3 = array();
$scorer4 = array();

$scorer1 = explode('^^^',$teams[0]['team1_scorer']);
$scorer2 = explode('^^^',$teams[0]['team2_scorer']);
$scorer3 = explode('^^^',$predictions[$p]['scorer1']);
$scorer4 = explode('^^^',$predictions[$p]['scorer2']);

$available = array_diff_assoc($scorer1, $scorer3);

#print_r($available);

$available1 = array_diff_assoc($scorer2, $scorer4);

#print_r($available1);

if(count($available)>0&&count($available1)>0){
$points = $points+2;
}

if ($InsertedR[0]['result'] == 0){

$points = 0;
}else{
$points = $points;

}

}

//echo $week.'==='.$week_points;
$week_points = $week_points+$points;

}

$prediction_points =$week_points+$prediction_points ;

// echo $total_points.'=====';

}

?>

How input the week_points into database now, since i have created column in mysql weekPoints. the data will be insert based on user_id per user. how to do it?

]]>
By: Greg Allard http://codespatter.com/2008/07/22/conditions-on-count-or-sum-in-mysql/comment-page-1/#comment-15194 Greg Allard Fri, 28 Aug 2009 20:30:02 +0000 http://codespatter.com/?p=42#comment-15194 yeah that looks like it should work yeah that looks like it should work

]]>
By: jarnail http://codespatter.com/2008/07/22/conditions-on-count-or-sum-in-mysql/comment-page-1/#comment-15193 jarnail Fri, 28 Aug 2009 15:27:29 +0000 http://codespatter.com/?p=42#comment-15193 Hello <br><br>I just did it.<br><br>I used this:<br> SELECT count(products_id) as count_products , SUM( reviews_rating ) as total FROM TABLE WHERE products_id=".$product_id; Hello

I just did it.

I used this:
SELECT count(products_id) as count_products , SUM( reviews_rating ) as total FROM TABLE WHERE products_id=”.$product_id;

]]>
By: jarnail http://codespatter.com/2008/07/22/conditions-on-count-or-sum-in-mysql/comment-page-1/#comment-15192 jarnail Fri, 28 Aug 2009 15:09:42 +0000 http://codespatter.com/?p=42#comment-15192 Can we do count and sum in single SQL?<br><br>I have table where i need SUM of a field as will as I have to COUNT total rows.<br><br>Any idea? Can we do count and sum in single SQL?

I have table where i need SUM of a field as will as I have to COUNT total rows.

Any idea?

]]>
By: buellart http://codespatter.com/2008/07/22/conditions-on-count-or-sum-in-mysql/comment-page-1/#comment-15189 buellart Tue, 04 Aug 2009 09:05:54 +0000 http://codespatter.com/?p=42#comment-15189 ah, thanx Greg, that gave me a kick in the back! ah, thanx Greg, that gave me a kick in the back!

]]>
By: suresh vijayan http://codespatter.com/2008/07/22/conditions-on-count-or-sum-in-mysql/comment-page-1/#comment-13931 suresh vijayan Wed, 27 Aug 2008 11:41:37 +0000 http://codespatter.com/?p=42#comment-13931 hi <br>myself suresh...a great programmer...if anybody needs help..just mail to me. hi
myself suresh…a great programmer…if anybody needs help..just mail to me.

]]>
By: Luciano http://codespatter.com/2008/07/22/conditions-on-count-or-sum-in-mysql/comment-page-1/#comment-13317 Luciano Wed, 23 Jul 2008 01:38:23 +0000 http://codespatter.com/?p=42#comment-13317 It's a good tip, thanks. It's a good tip, thanks.

]]>
By: Luciano http://codespatter.com/2008/07/22/conditions-on-count-or-sum-in-mysql/comment-page-1/#comment-10942 Luciano Wed, 23 Jul 2008 00:38:23 +0000 http://codespatter.com/?p=42#comment-10942 It's a good tip, thanks. It’s a good tip, thanks.

]]>
By: clause http://codespatter.com/2008/07/22/conditions-on-count-or-sum-in-mysql/comment-page-1/#comment-10918 clause Tue, 22 Jul 2008 17:17:02 +0000 http://codespatter.com/?p=42#comment-10918 [...] [...] [...] [...]

]]>