Jump to content

for loop help?


crossfuse

Recommended Posts

http://cpsc.maconstate.edu/1010/chapter3/drivecube.php

 

i'm trying to make a site like this for my php program but with a textbox instead where you can type in numbers...i know it includes this code:

------------------------------

for ( $i = 0; $i < $max; $i++ ) {

  Set of statements to repeat

}

 

and

 

while ($ctr < $max) {

Set of statements to repeat

}

------------------

 

i'm a newb so if i could get some help i would appreciate it

Link to comment
https://forums.phpfreaks.com/topic/151670-for-loop-help/
Share on other sites

you just need one loop really and within that loop you can calculate the values of a square and cube

for ( $i = 0; $i < $max; $i++ ) {
   $square=your_calculation_here;
   $cube=your_calculation_here;
   echo some_of_your_calculated_values_here;
}

Link to comment
https://forums.phpfreaks.com/topic/151670-for-loop-help/#findComment-796669
Share on other sites

ok that looks about, but something's still wrong...i get this error:

 

Parse error: syntax error, unexpected T_FOR in /usr/local/www/cpsc/students/justin.ham/square.php on line 26

 

http://cpsc.maconstate.edu/students/justin.ham/square.html

 

that's the website i have and here's the PHP code for receiving.

 

<html>

<body>

<?php

 

$number = $_POST["number"];

 

 

$number2 = (1) ;

 

$sum = ($number + $number2) ;

 

 

print("<br> The number plus 1 is $sum");

 

 

?>

<br><br>

<font size="4" color="blue"> Table of Square Values</font><br>

<table border= 1>

<th> Number</th><th>Sqr </th>

<?php

$max=$number

 

for($i = 0; $i < $max; ++$i){

echo "<input type='text' name='data[]' /><br />";

}

 

 

?>

</body>

</html>

 

i really have no clue how to make this work...

Link to comment
https://forums.phpfreaks.com/topic/151670-for-loop-help/#findComment-797170
Share on other sites

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.