Thread: help for (for)
View Single Post
Old Mar 28th, 2008, 6:15 AM   #2
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: help for (for)

Couple of things, firtsly could you use code tags to place code in a post.

Secondly welcome to the forums.

OK one of your first problems was your initial for statement had seom variables named wrongly

PHP Syntax (Toggle Plain Text)
  1. for($cvchk = 1; $cchk <= $c; $cchk ++)

then there were a few other problems to such as at no point were you specifying to start from any number other than 1, so it would always count from 1-4.

you were also echoing the value of cchk for no reason.

here is the code i come up with not the best for many reasons, such as im not a great programmer/scripter plus i don't know the PHP language but here it is anyway

PHP Syntax (Toggle Plain Text)
  1. <?
  2. $c = $_POST['col'];
  3. $r = $_POST['rw'];
  4. ?>
  5.  
  6. <?
  7. for($cvchk = 1; $cvchk <= $c; $cvchk ++)
  8. {
  9. $x = $cvchk;
  10. for($rchk = 1; $rchk <= $r; $rchk ++)
  11. {
  12. if ($x > 4)
  13. {
  14. $x = 1;
  15. }
  16. echo $x." ";
  17. $x += 1;
  18. }
  19. echo "<br />";
  20. }
  21. ?>

As you can see i also check to see if x goes above 4 if so it returns it to 1, this ensure that it doesn't produce this outcome

1234
2345
3456
4567

Also this is unchecked but to make this work for any number of rows, so the highest number = the number of ros simple change this

PHP Syntax (Toggle Plain Text)
  1. if ($x > 4)
  2. {
  3. $x = 1;
  4. }
  5. .....
  6. if ($x > $r)
  7. {
  8. $x = 1;
  9. }


Hope this helped if you need anything else just ask.
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm

Last edited by Freaky Chris; Mar 28th, 2008 at 6:30 AM.
Freaky Chris is offline   Reply With Quote