Anyone care to help an amateur?

Hello! I am total newbie taking an out-of-department course called Database Management because I love logic and thought I may enjoy learning some beginning PHP coding. Appartently, I stink. :-[

I have a very basic assignment to create tables of multiplication facts. I am doing this using a for loop and the numbers/multiplication looks fine. However, I need to group each set into its own table (or div…it doesn’t really matter how i group them) and I can’t seem to figure out how to do this. Since the script is running in a loop, I can’t seem to understand how to nest things so that I can refer to a variable before it starts counting up to the next value. (I’m wondering if I am even in the ‘know’ enough to explain my stupid question!?)

In other words, I’m ending up with each math fact as its own little entity when I’m actually trying to say that all the 1’s are grouped together…all the 2’s…etc.

Thanks for any suggestions!
Lorrie

Do you have any code or even a mockup to help us understand better what you’re trying to accomplish?

I’m a wee embarrassed to post this code, considering how elementary it is… but, thank you. (Next time, I’ll post to the beginner’s forum) The commented out stuff on the bottom is some of my prior attempts to wrap each group into a table. (all the 1’s together, etc) I realize I have to get that command out of the loop somehow, but I don’t know how to do that and still call the variables.

[code]

Multiplication Tables

table, td, th {
border: 1px solid green;
}

th {
background-color: green;
color: white;
}

Multiplication Facts

<?php for ($c = 1; $c < 11; $c++) { for ($m = 1; $m < 13; $m++) { $a = $c * $m; if ($c==1) { echo "$c * $m = $a
";} }} //echo "

Cheat Sheet for $c

"; { //if ($c==1) { //echo "

Cheat Sheet for $c

"; //echo "$c * $m = $a
";} //if ($c==1) { //echo " //$c * $m = $a
";} ?> [/code]

This will space out the figure groups. You actually were on the right track, just needed to change some of the variables around in your if statement.
[php]

Multiplication Tables

table, td, th {border: 1px solid green;}
th {
background-color: green;
color: white;
}

Multiplication Facts

<?php $a = 0; $next = ''; $ct = 0; echo "
\n"; for($c = 1; $c < 13; $c++) { for ($m = 1; $m < 13; $m++) { $a = $c * $m; if($m != $next) { echo "$c * $m = $a
\n"; $next = $m; } } $ct++; if($ct == 6) { echo "


\n
\n"; } else { echo "
\n"; } } ?>
[/php]This will output 1x1 up through 12x12 in 2 rows, I couldn't get it to work right using more than 2.

I love the interwebs. : ) I certainly would not have done that myself… I think I’m a little too new to understand how to dig my way out of the hole, but I very (MUCH!) appreciate being able to see the code that would be successful. Thank you!!!

Sponsor our Newsletter | Privacy Policy | Terms of Service