Jump to content

[SOLVED] Problem with php estimate


a-mo

Recommended Posts

Hi,

 

I'm new here so I'm not sure sure to post in the right place or in the right way.

I have a problem. I'm trying to propose an on-line estimate on my site, using php. The problem is the "echo" at the end of the script doesn't seem to echo anything.

 

Here's the code:

 

<?php

 

function indication()

 

{

 

$Input=array();

$Input[0]=$_GET["ecma"];

$Input[1]=$_GET["php"];

 

$IndexSum=array_sum($Input);

$Index=$IndexSum+1;

 

$PageNb=$_GET["page_nb"];

$PageTran=$PageNb*90;

$Pages=$PageTran+180;

 

$Total=$Pages*$Index;

 

echo $Total;

}

 

?>

 

Any ideas?

 

I'm new to php, it may be something obvious.

 

Many thanks.

Link to comment
https://forums.phpfreaks.com/topic/124041-solved-problem-with-php-estimate/
Share on other sites

3 pointers:

 

1.  Why is it a function?  I see no point in having this a function.

 

2.  Why go through all that trouble of making like, 3 arrays and doing simple arithmetic when you can just do:

 

<?php
$index = ($_GET['ecma'] + $_GET['php']) + 1;
$pages = ($_GET['page_nb'] * 90) + 180;
echo $index * $pages;
?>

 

3.  I'd really suggest starting variables with a lowercase letter and then use camelCase. It makes it easier to not lose track of a variable's case.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.