Jump to content

Recommended Posts

Hi

I'm tyring to do this calculation, shown below:

 

$Height='Height';

$S1Weight='S1Weight';

$result= ($Height * $Height / $S1Weight);

echo ($result);

 

Another way i tried was:

 

print ("BMI for Session 1 is: ");

print ("S1Weight FROM `main` WHERE clientID='1'" * "S2Weight FROM `main` WHERE clientID='1'" / "Height FROM `main` WHERE clientID='1'");

 

It gives me an error: 'Division by zero', There are figures in all the fields i am using ,i.e. Height and S1Weight and i am trying to individualise to to clientID. Any ideas why it throws this error?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/151784-calculations-in-php/
Share on other sites

What i am trying to do is use the fields from my database (S1Weight and Height) to work out this calculation. I am a new programmer and not sure if I'm doing this the right way. I have tried many different ways but none have been successful. The code i am using now is:

 

<?php 
$query="SELECT Height FROM `main` WHERE clientD='1'"; 
$result=mysql_query($query); 
$row = mysql_fetch_assoc($result); 
echo $row['Height'];
?>
<br>
<?php
$query="SELECT S1Weight FROM `main` WHERE PatientID='1'"; 
$result=mysql_query($query); 
$row1 = mysql_fetch_assoc($result); 
echo $row1['S1Weight']; 
?>
<br>
<?php
$c=($row*$row/$row1);
echo $c;
?>

 

The first two parts display the Height and S1Weight individually but when i put it into the calculation i need i throws an error, 'Fatal error: Unsupported operand types'.

Firstly is this the correct code and if it is how could i go about resolving this error. If not, can you direct me the right way.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/151784-calculations-in-php/#findComment-797634
Share on other sites

<?php 
$query="SELECT Height FROM `main` WHERE clientD='1'"; 
$result=mysql_query($query); 
$row = mysql_fetch_assoc($result); 
echo $h = $row['Height'];
?>
<br>
<?php
$query="SELECT S1Weight FROM `main` WHERE PatientID='1'"; 
$result=mysql_query($query); 
$row1 = mysql_fetch_assoc($result); 
echo $w = $row1['S1Weight']; 
?>
<br>
<?php
$c=$w!=0 ? ($h*$h/$w) : 'S1Weight is zero!';
echo $c;
?>

 

Link to comment
https://forums.phpfreaks.com/topic/151784-calculations-in-php/#findComment-797724
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.