Jump to content

STuck on where to start on a variable


swanside

Recommended Posts

Hi all,

 

I am stuck now, I have a test database and I have made some search pages which return the results from a detail page when a specific item is clicked on. In one of the results field, there is a colume called addition_Cost. This is a percentage markup, but how do I get the info from this colume to put it into a variable to perform a maths sum?

Cheers

Link to comment
Share on other sites

<?php

$query = "SELECT addition_Cost FROM table_name WHERE (...not sure of your condition)";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);

echo $row['addition_Cost']; //This row holds the percentage from DB

?>

 

If you want more specifics on the query condition, your going to have to explain more. How do you want to determine what row to pull the value from?

 

 

Link to comment
Share on other sites

<?php

$query = "SELECT addition_Cost FROM table_name WHERE (...not sure of your condition)";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_assoc($result);

echo $row['addition_Cost']; //This row holds the percentage from DB

?>

 

If you want more specifics on the query condition, your going to have to explain more. How do you want to determine what row to pull the value from?

 

 

 

To answer your question on how to add the % into a mathematical statement simply do the above, but when echoing out the $row do this.

 

$percent = $row['addition_Cost'];

//Then create your math phrase how you need it adding the variable.

$math_result = 600*$percent;

//Then display the results with this phrase.
echo $math_result;

 

If you have question just ask.

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.