Hi..

i'm basically a novice in php and have been trying to work out on a multiplication tables using textboxes (to arrive at the square of each number using loops). Given below is the code. Herein i'm not sure as to how to define the variable component which needs to change for each value in the loop.

The code

<?php
// Loop through actions for count
$eg_i = 1;
for(; $eg_i < 11; $eg_i++)
{

}
$eg_calc_1 = @(  $_POST['1Text"<?php echo  $eg_i ?>"'] * $_POST['2Text"<?php echo  $eg_i ?>"']);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>Untitled</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
    <form id="Form1" style="WIDTH: 100%; HEIGHT: 143px" action="<?php echo  $_SERVER['PHP_SELF'].(@($_SERVER['QUERY_STRING'] > ' ') ? '?'.$_SERVER['QUERY_STRING'] : '') ?>" method="post">
        <?php
// Loop through elements for count
$eg_i = 1;
for(; $eg_i < 11; $eg_i++)
{
?>

<p>
                <input id="1Text<?php echo  $eg_i ?>" value="<?php echo  $eg_i ?>" name="1Text<?php echo  $eg_i ?>">&nbsp;x 
                <input id="2Text<?php echo  $eg_i ?>" value="<?php echo  $eg_i ?>" name="2Text<?php echo  $eg_i ?>">&nbsp;=&nbsp; <span id="span1"><?php echo  $eg_calc_1 ?></span>
            </p>

<?php
}
?>
        <p>
            &nbsp;
        </p>
        <p>
            <input id="Submit1" type="submit" value="Submit Form" name="Submit1">
        </p>
    </form>
</body>
</html>

I would be really grateful if you can assist me in solving this problem.

Regards
Vijay

Member Avatar for diafol

Sorry, got white line tag fever. If you don't put your code between code tags, it's really difficult to read, so I'll just take from your blurb you're looking to multiply or square numbers:

$square = pow ( $base, 2 );

assign each input item thus:

loop this output however many times you wish:

<input type="text" name="first[]" />
<input type="text" name="second[]" />

(see below for fuller code for this section)


receive values via $_POST[x] and $_POST[x]

loop from 0 to count($_POST - 1)

$answer[] = $_POST['first'][x] * $_POST['second'][x]

in your form:
loop through no. of inputs

//set $post1 and $post2 to "" each time before this
if(isset($_POST['first'][x]))$post1 = $_POST['first'][x]; 
if(isset($_POST['second'][x]))$post2 = $_POST['second'][x];

echo "<input type='text' name='first[]' value='{$post1}' />";
echo "<input type='text' name='second[]' value='{$post2}' />";
echo "<input type='text' name='answer[]' value='{$answer[x]}' />";

I'm sure you get the idea. This is really rushed, so you could probably cut this down and make it much more efficient.

Dear Ardav,

Thanks for your help. Will take ur advice and shall work on it..

Thanks once again.

Regards
Vijay

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.