Jump to content

[SOLVED] calculations within a field


bhavin_85

Recommended Posts

hey guys

 

i have a field which is float, it stored the price of an item, i need to create another field called points which times the price by 0.1 and stores that value.

 

how would i do this? can the sql database do it itself or would i need to create a function in php that will convert it then store the points?

 

cheers

 

Link to comment
Share on other sites

ok so i guess from what ur saying ill have to write the code in my form which enters the info into that database, ill have a go at it

 

What thorpe is suggesting is to let your SQL do it. I agree with him because you would simply have to write a single query to update all the fields. Once you add your new field, just run the query he posted above, and it will update the whole table for you.

Link to comment
Share on other sites

You can run mysql from .php pages.

 

Just set the query into a variable like so:

 

$sql = "PUT QUERY HERE (e.g. SELECT BLAH FROM BLAH/UPDATE diggerydoo)";
mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); 

 

put that in your page and you'll see, replace "PUT QUERY HERE" with the query (rolls eyes)

 

Snooble

Link to comment
Share on other sites

thought there might be a way to make the sql database exectute the query automatically everytime a new row is added

 

Depending on your version of mysql you may be able to use triggers. Im not 100% up on there syntax but check the mysql manual.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.