473,383 Members | 1,925 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,383 software developers and data experts.

How make value of field to be mathematical equation

w33nie
56
My table is pretty well complete, but I would prefer it if the value for Points could be turned into a mathematical equation,
and this equation would use the data from the other fields in the table to achieve a value.

I want this done in phpMyAdmin 2.7, if possible, so that when I change the values in other fields, the Points variable changes, due to its equation.

The equation I would want would be something like:
"won * 3 + drawn * 1"
(won and drawn are 2 other fields in my database)
and have this equation become the value of my Points field.

and would it be possible to have more than one variable as an equation?


I doubt you'll need the php code from my page, but here it is anyway.
Expand|Select|Wrap|Line Numbers
  1. <? $hostname = "***.secureserver.net"; // The mySQL DB server. 
  2. $username = "acssl_table"; // The username you created for this database. 
  3. $password = "Victoria3"; // The password you created for the username. 
  4. $usertable = "table"; // The name of the table you made. 
  5. $dbName = "acssl_table"; // This is the name of the database you made. 
  6.  
  7. MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
  8. @mysql_select_db( "$dbName") or die( "Unable to select database"); 
  9. ?> 
  10. <? 
  11. //error message (not found message)begins 
  12. $XX = "No Record Found, to search again please close this window"; 
  13. //query details table begins
  14. $query = mysql_query("SELECT * FROM `table` ORDER BY points DESC, g_difference DESC, g_for DESC LIMIT 0, 30 "); 
  15. while ($row = @mysql_fetch_array($query)) 
  16. $variable1=$row["team"];
  17. $variable2=$row["played"]; 
  18. $variable3=$row["won"]; 
  19. $variable4=$row["drawn"];
  20. $variable5=$row["lost"];
  21. $variable6=$row["g_for"]; 
  22. $variable7=$row["g_against"]; 
  23. $variable8=$row["g_difference"]; 
  24. $variable9=$row["points"];
  25. //table layout for results 
  26.  
  27. print ("<tr>");
  28. print ("<td width='150'><span class='BodyTable'>$variable1</span></td>");
  29. print ("<td width='50' align='center'><span class='BodyTable'>$variable2</span></td>");
  30. print ("<td width='50' align='center'><span class='BodyTable'>$variable3</span></td>");
  31. print ("<td width='50' align='center'><span class='BodyTable'>$variable4</span></td>");
  32. print ("<td width='50' align='center'><span class='BodyTable'>$variable5</span></td>");
  33. print ("<td width='50' align='center'><span class='BodyTable'>$variable6</span></td>");
  34. print ("<td width='50' align='center'><span class='BodyTable'>$variable7</span></td>");
  35. print ("<td width='75' align='center'><span class='BodyTable'>$variable8</span></td>");
  36. print ("<td width='75' align='center'><span class='BodyTable'>$variable9</span></td>");
  37. print ("</tr>"); 
  38. }
  39. //below this is the function for no record!!
  40. if (!$variable1)
  41. print ("$XX");
  42. //end 
  43. ?>
Feb 10 '07 #1
5 3036
ronverdonk
4,258 Expert 4TB
Simply: you cannot.

A database is to hold (atomic) data and is not a replacement for a spreadsheet.

Any calculations on that data can be done using an SQL statement with the builtin functions..

Ronald :cool:
Feb 11 '07 #2
w33nie
56
how would I be able to get those fields to become math equations then?
Feb 12 '07 #3
ronverdonk
4,258 Expert 4TB
how would I be able to get those fields to become math equations then?
Like this, just SQL arithmetic:
Expand|Select|Wrap|Line Numbers
  1. mysql> select * from test;
  2. +------+--------+------+-------+
  3. | id   | team   | won  | drawn |
  4. +------+--------+------+-------+
  5. |    1 | Team 1 |    3 |     2 |
  6. |    2 | Team 2 |    4 |     0 |
  7. |    3 | Team 3 |    0 |     4 |
  8. +------+--------+------+-------+
  9. 3 rows in set (0.00 sec)
  10.  
  11. mysql> select team, (won*3+drawn*1) as total from test;
  12. +--------+-------+
  13. | team   | total |
  14. +--------+-------+
  15. | Team 1 |    11 |
  16. | Team 2 |    12 |
  17. | Team 3 |     4 |
  18. +--------+-------+
  19. 3 rows in set (0.00 sec)
Ronald :cool:
Feb 12 '07 #4
w33nie
56
how would i implement that into my php script?

i really have no idea where to start or what to do.
Feb 13 '07 #5
ronverdonk
4,258 Expert 4TB
Starting at the $query, the code would be as follows. Notice

(1) the change in the SELECT statement
(2) that $variable5a holds the calculated field 'total_points'.

[php]$query = mysql_query("SELECT *, (won*3+drawn*1) as total_points FROM `table` ORDER BY total_points DESC, g_difference DESC, g_for DESC LIMIT 0, 30 ");
while ($row = @mysql_fetch_array($query))
{
$variable1=$row["team"];
$variable2=$row["played"];
$variable3=$row["won"];
$variable4=$row["drawn"];
$variable5=$row["lost"];
$variable5a=$row['total_points'];
$variable6=$row["g_for"];
$variable7=$row["g_against"];
$variable8=$row["g_difference"];
$variable9=$row["points"];
//table layout for results

print ("<tr>");
print ("<td width='150'><span class='BodyTable'>$variable1</span></td>");
print ("<td width='50' align='center'><span class='BodyTable'>$variable2</span></td>");
print ("<td width='50' align='center'><span class='BodyTable'>$variable3</span></td>");
print ("<td width='50' align='center'><span class='BodyTable'>$variable4</span></td>");
print ("<td width='50' align='center'><span class='BodyTable'>$variable5</span></td>");
print ("<td width='50' align='center'><span class='BodyTable'>$variable5a</span></td>");
print ("<td width='50' align='center'><span class='BodyTable'>$variable6</span></td>");
print ("<td width='50' align='center'><span class='BodyTable'>$variable7</span></td>");
print ("<td width='75' align='center'><span class='BodyTable'>$variable8</span></td>");
print ("<td width='75' align='center'><span class='BodyTable'>$variable9</span></td>");
print ("</tr>");
}[/php]

Ronald :cool:
Feb 13 '07 #6

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

Similar topics

1
by: Sam | last post by:
Hi, I don't know how to specify the display and value field for a combobox when using AddRange to fill the combo. Here is what I have so far: -A function to build an array of object : Dim...
1
by: arulbenito | last post by:
i need to write a xml data inside the value field in web.config file. it looks likes this <configuration> <appSettings> <add key="MyXmlData" value="<data><type></type>........." />...
6
by: reshmidoudou | last post by:
I am new to c++ and have to write a program that takes a line of characters as its inout and represents a mathematical eqaution of the form a + b = c and checks whether it is correct. example 2 + 3 =...
1
by: somanyusernamesaretakenal | last post by:
Hi everyone, I am working with Access 2003. I know a crosstab query only allows 1 value field, but how to do you around this restriction? I have a table with let’s say customers, products,...
10
by: Hugh Middity2 | last post by:
Hello, is there a parameter value field in access that can be passed between queries, forms and reports? For example, we have two companies both selling the same products. To extract data we have to...
4
by: AR123 | last post by:
In the field for employee contribution I want to have GBP and make sure that this prints out in the results email. How can I set it up so that the GBP display next to the value in the results email?...
3
by: gelong83 | last post by:
Guyz, I really need help on this. I'm trying to make some mathematical programming. We can input any equation and then the compiler will detect how many variables was (on the equation). After...
15
by: amy1 | last post by:
Hello everyone, I'm new here and new to Access2007 as well! I have a multi-value field in a form, and would like to calculate the total of the selected values in this field and place the...
19
by: jaad | last post by:
how do you reference a single value field to a multi-value field? I sometime use a macro in form1 to open form 2 containing the same ID example: Open form: WorkOrder where condition: ="="...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.