Jump to content

Php Not Doing Sum Operation On Sql Query Variables With Number.


gdeliana

Recommended Posts

Ok, i think this is the best place for this question. I have the following problem that no matter what i do the number doesn't add to the sql variable. $i=interest rate, which is a row in sql database, i need to add 1 to it. The result is 1. Which should have been for example 1.01 if $i=1. Here is the code:

 

 

$result1 = mysql_query("SELECT interest_rate FROM list1") or die(mysql_error());
$row1 = mysql_fetch_array($result1);
$i = $row1['interest_rate'];
echo $i . "<br/>";
echo $i+1 . "<br/>";

 

On echo $i i get the row values. On $i+1 i get only 1 in a column repeated vertically. WHY?? PLSSSSS help!!!!

Edited by gdeliana
Link to comment
Share on other sites

So ok i'm using xampp server. What's the damn problem, is keeping me all the day here. Do i need to use any parameter when fetching the array. Maybe the array is not considered as numbers. In sql (phpmyadmin) i have the type of row set as int(6), encoding:UTF8.

 

Edit: sorry no encoding is set for this row.

Edited by gdeliana
Link to comment
Share on other sites

How are you getting a decimal value back from an INT field? An INT field will convert any decimal value to an INTeger. The field should be FLOAT, DOUBLE or DECIMAL.

 

The values are from $i are: 0.01; 0.02; ..........etc. Do i need to type here 35 rows?? I get the same values weather i change it to: decimal, int, float.

Link to comment
Share on other sites

You're certainly not getting a value of 0.01 from an INT field in the database. What is it you're trying to accomplish with this?

 

I want to create a form for helping out customers for choosing banks, where to deposit. I have in a database all the requirements of each bank (like minimal deposit, interest rate and so on) So i need to fetch the database according to user input and at the same time from those results, the code must be able to calculate the future value of the deposit in the selected banks which fulfill the customer requirements.

Link to comment
Share on other sites

I want to create a form for helping out customers for choosing banks, where to deposit. I have in a database all the requirements of each bank (like minimal deposit, interest rate and so on) So i need to fetch the database according to user input and at the same time from those results, the code must be able to calculate the future value of the deposit in the selected banks which fulfill the customer requirements.

 

I have found the problem: the interest column was in varchar :D....i guess it's always my fault :D. Thanks buddies!!! Really!!! I am trying to output the results with echo, but the problem is as i concatenate a lot of php variables and strings i cannot insert HTML markup, coz i always must end the first part of the bracket and than concatenate another value. How do i put the entire echo result in a div as i have a lot of concatenations. :)

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.