473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to divide two values from a data table ensuring that it is not divided by zero?

Hello,

I am trying to divide one value from my data table with an associated ID by another value from my data table with a different ID for the same day that the value was added to the data table.

I update my data table daily with several values that have different IDs that label the value type.

Certain of the values I add to my data table also have a value of 0. Therefore, if I want to divide one value by another, I have to ensure that the rows that contain a value of 0 are not counted.

After I divide all of the values into a new value, I then need to store that value in my data table with a new ID so that I can differentiate it.

I have some code that I've been working on but am getting tricked up at this point and would appreciate any further assistance.

Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3.   function getValue ( $iPlayer, $iStat ) {
  4.     $sql = sprintf( "SELECT value FROM data WHERE player_id = '%d' and statistic_id = '%d' and day = CURdate()", $iPlayer, $iStat);
  5.     $result = mysql_query ( $sql );
  6.   }
  7.  
  8.   function getListofPlayers ( ) {
  9.     $sql = 'SELECT player_id FROM data WHERE day = CURdate()';
  10.     $result = mysql_query ( $sql );
  11.   }
  12.  
  13.   function storeValue ( $iPlayer, $iStat, $value ) {
  14.     $sql = sprintf( "INSERT INTO data SET player_id = '%d', statistic_id = '%d', value = '%s', day = NOW()", $iPlayer,  $iStat,  $value );
  15.     $result = mysql_query ( $sql );
  16.   }
  17.  
  18.   $aPlayer = getListOfPlayers();
  19.   foreach ( $aPlayer as $oPlayer ) {
  20.  
  21.    $stat_id_1 = 9;
  22.    $stat_id_2 = 4;
  23.    $stat_id_new = 39;
  24.  
  25.     $a = getValue( $oPlayer->id, $stat_id_1 );
  26.     $b = getValue( $oPlayer->id, $stat_id_2 );
  27.     $c = $a / $b;
  28.  
  29.    storeValue ( $oPlayer->id, $stat_id_new, $c );
  30.  
  31.   }
  32.  
  33. ?>
  34.  
Sep 17 '10 #1
1 2595
Markus
6,050 Expert 4TB
Check if the value is 0?

Expand|Select|Wrap|Line Numbers
  1. if variable equals 0
  2.   do not divide
  3. else
  4.   do divide
  5. endif
  6.  
Sep 17 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kevin Myers | last post by:
Hello, I'm an experienced application developer in some languages (including various SQL dialects), but have very little experience with MS Access or VBA, and am having trouble figuring out how...
1
by: Vasilis X | last post by:
Here is the question : I have a data table, UnShorted, which has a data column EventTime (type : date time) and a data column Values (type : single). I want to create a table, Shorted, that...
1
by: Kwok | last post by:
In my project... which deadline is July 3 .... I need to design a very simple database.... which can enter some subject or subheading in a document to a data table in MS access. I use VB to...
1
by: DH | last post by:
I have an untyped dataset with a table. I am trying to programmatically add a row to this table. This was working in VS 2003 / .net 1.1 I am receiving an error "Object reference not set to an...
2
by: joel | last post by:
Hi Guys ... I need some help on this... i know i've followed the right declarations on this.. or if not i may be close on hitting it. And i know there's something wrong with this code. This is...
7
by: riceking | last post by:
Is it possible to do the following and if so, how? In one table, I have a list of email addresses I know are bad and no longer work. Another table has a list of companies with contact people,...
1
by: san1014 | last post by:
Hi I have a table SQL> select * from nodes; NODE_ID NODE_NAME -------------------- ------------------------------ N1 Kothhapet N2 Nagole...
1
by: drwigginton | last post by:
I have created several bar charts in MS Access using query results to provide the data for the chart. I added data tables to the charts to show the actual values. My problem is that one of the fields...
14
by: Mark | last post by:
I have a table with a field that uses a combobox to populate values. The Lookup tab within table design mode is the following: Display Control Combo Box Row Source Type ...
0
by: krisssgopi | last post by:
Hi Team, While am using the below code it was throwing an exception update unable to find table mapping or data table customer. Please help me in this regard. Private Sub Button1_Click(ByVal...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.