Operator Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hammer136
Forum Commoner
Posts: 29
Joined: Sat Mar 19, 2005 12:18 pm

Operator Problem

Post by Hammer136 »

Hi

I have a problem in which i have a table with some numbers in it and i wish to multiply the number in the table by a number given in from a form so i came up with this

Code: Select all

$multiplier[priv] = "select Multiplier from Strength where Unit = Private";
$multiplier[cnsrpt] = "select Multiplier from Strength where Unit = Conscript";

$priv = '".$_POST["private"]."';
$cnsrpt = '".$_POST["conscript"]."';

$score[att] = ($multiplier[priv] * $priv);
$score[def] = ($multiplier[cnsrpt] * $cnsrpt);

echo "$score[def]";

?>
This however when i run it with the html always gives me an answer of 0.

Any suggestions welcome

Thanks
Hammer
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

where do you execute the queries?
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Why are you trying to multiply a integer by a string?

Code: Select all

$scoreї&quote;def&quote;] = ($multiplierї&quote;cnsrpt&quote;] * $cnsrpt);

Code: Select all

<?
$multiplier["priv"] = "select Multiplier from Strength where Unit = Private";
$multiplier["cnsrpt"] = "select Multiplier from Strength where Unit = Conscript"; 
$priv = $_POST["private"];
$cnsrpt = $_POST["conscript"]; 
$score["att"] = ($multiplier["priv"] * $priv);
$score["def"] = ($multiplier["cnsrpt"] * $cnsrpt); 
echo $score["def"]; 
?>
also make sure you are using a POST form not a GET form.
Hammer136
Forum Commoner
Posts: 29
Joined: Sat Mar 19, 2005 12:18 pm

Post by Hammer136 »

Thanx but what uve just given me gives out the same results.

It could be the values in the tables but im sure ive got those right

Im multiplying a number which is entered in from a form by a number in a table. Is there an easier way to do this?

Thanx
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

please tell me where the execution of the querioes occur.

At the moment, you code makes no sense
Hammer136
Forum Commoner
Posts: 29
Joined: Sat Mar 19, 2005 12:18 pm

Post by Hammer136 »

The code is executed from a html file with the code

Code: Select all

<html>
<head>
</head>

<body>

<form action="battle.php" method="post">
Privates: <input type="text" name="private" size="20"><br>
Conscripts: <input type="text" name="conscript" size="20"><br>
<input type="submit" value="Log In">
</form>

</body>
</html>
Is this what you mean?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

perhaps i am not being clear!?

I am guessing that this...

Code: Select all

select Multiplier from Strength where Unit = Private
...is as query and you are returning some results from a database.

A not point do you execute that query to return any information from the table in your database.
Hammer136
Forum Commoner
Posts: 29
Joined: Sat Mar 19, 2005 12:18 pm

Post by Hammer136 »

Oh right i get you. Wat do i need to add to execute it?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

You really should learn the basics of PHP and MySQL

Heres a starter http://uk2.php.net/manual/en/function.mysql-result.php
Post Reply