473,581 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

75 New Member
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 2635
Markus
6,050 Recognized Expert Expert
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
2477
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 to even get started with the following seemingly simple task... I have a table with a composite primary key made up of three columns. The lowest...
1
1593
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 will have all values of UnShorted but they will be shorted by EventTime. I try this : dim Results as New DataRow( ) = UnShorted.Select (...
1
1602
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 implement this, tsubject <-- is the text box name the code show as follow: "INSERT INTO data (subject) values ("""+trim(Me.tsubject)+""");" I think...
1
1884
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 instance of an object." Here is the code that worked in VS 2003 / .net 1.1: row = dtLines.NewRow()
2
1264
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 what i did... it adds a new row into the data table... with values like department, sales glcode etc. when i click the insert/add button it creates...
7
1941
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, fields accommodate up to ten people. There's a corresponding field for each one for their email address. In other words, the table has 10 different...
1
3765
by: san1014 | last post by:
Hi I have a table SQL> select * from nodes; NODE_ID NODE_NAME -------------------- ------------------------------ N1 Kothhapet N2 Nagole N3 Uppal
1
4183
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 in the data table continues to display a number with several decimal places showing (i.e., 7.120000054). The query field that provides the number...
14
6539
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 Table/Query Row Source SELECT .LastName, .FirstName, .EmployeeNumber FROM ; Bound Column 3 Column Count 3...
0
1582
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 sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try con.Open() param.ParameterName =...
0
8156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7910
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6563
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.