PDA

View Full Version : Deviding 2 stored values. Should be possible.


Spider
Fri 25th May '01, 9:08pm
Hi there everybody!

I was wondering how I could devide 2 values and
show the result..

Let me explain it a little more.
Let's say I have stored 2 values like this:

$valueone=10;
$valuetwo=5;

Now I would like to do something like this:

$devided=$valueone/$valuetwo;
echo $devided;

So the result of deviding $valueone by $valuetwo
stored in $devided.

I hope I'm making myself a little bit clear. :)
I dunno how else to explain it.

Thank you in advance.

Mas*Mind
Fri 25th May '01, 9:16pm
Your example is exactly how it should be working...

Spider
Fri 25th May '01, 9:20pm
When I try to do it like that I get the following
message:

Fatal error: Unsupported operand types

Thanks for your quick reply b.t.w. :)
Very much appreciated.

Greetings,
Spider

Mas*Mind
Fri 25th May '01, 9:23pm
This works perfectly for me:


<?php

$valueone=10;
$valuetwo=5;

$devided=$valueone/$valuetwo;
echo $devided;


?>


It's divided btw ;)

Spider
Fri 25th May '01, 9:30pm
You are right. It is divided. :)

When I run that script you just wrote it indeed
works fine. Let me explain a little more what I'm
doing.

I'm currently writing a "thread rating" hack for
vBulletin 1.1.5.

What I have is this:

$timesrated=$DB_site->query_first("SELECT timesrated FROM rate WHERE threadid=$threadid");
$oldrating=$DB_site->query_first("SELECT rating FROM rate WHERE threadid=$threadid");
$newrating=$oldrating/$timesrated;

Any more suggestions? Or am I really making a
stupid mistake there? :D

Greetings,
Spider

Mas*Mind
Fri 25th May '01, 9:37pm
The code seems ok.

But probably the resultset is empty or you get an error back. You should check first if it's an integer or something

if(is_integer($bla))
{ etc();
}

But try to echo the $vars so you can see what's happening.

and don't forget that dividing through zero (0) also isn't permitted. So you probably have to built in some check to make sure $timesrated isn't zero.

Spider
Fri 25th May '01, 9:40pm
The "check" for an existing value was already
build in. But thanks for noticing tho.

Anyways, I think I fixed it.
What I did now was:

$oldrating=$DB_site->query_first("SELECT timesrated,rating FROM rate WHERE threadid=$threadid");
$newrating=$oldrating[rating]/$oldrating[timesrated];

When I echo $newrating, I seems to be giving the
correct value. :)

I will test it some more.

Thank you very much for your time.

Greetings,
Spider