Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

for count question multiplying

Featured Replies

I got the following code list just for you guys;

 

<?php

for ($a=1, $b=1, $c=1;

$a<=24, $b<=24, $c<=24;

$a=$a*2, $b=$b*2, $c=$c*2)

print("$a<br>");

?>

 

Output of $a

1

2

4

8

16

 

I'm not a wizard when it comes to math but I thaugh when putting *2 it goes from 2 4 6 8 etc. That is the way I aqtually wanted put the output showed it goes differently namely 1 2 4 8 16 so it's aqtually multiplying the number itself by 2.

 

So any of you math geeks know what I must do, to get the result I aqtually want?

Edited by kensha

<?php
for ($a=2; $a<=24; $a+=2)
{
   print("$a<br>");
}
?>

 

$a's output is

2
4
6
8
10
12
14
16
18
20
22
24

 

Start it at the number you want to show up first, then rather that multiplying just += the incremented value.

 

You were saying $a = $a * 2;, which 1*2=2, 2(the result from the first time)*2=4, 4(again the result from previous time)*2=8 ... Since $a is always changing, the multiplication will also change, so it goes 1, 2, 4, 8 ...

Edited by markeh

  • Author

Yes, I indeed figured that one out when putting in the + :)

 

Anyway might be stupid but I'm stuck on another subject;, well stuck? I don't know for sure if the books is wrong or I have mis typed it in somewhere even after re-reading and re-typing it multiple times.

 

<?php

print("<tr>");//open table row

print("<th> </th>"); //open and close table header

for ($count_1 = $start_num;//intiële expressie

$count_1 <= $end_num;//terminatie controle

$count_1++);//lus einde expressie

print("<th>$count_1</th>");//Open and close th using variable $count_1

print("</tr>"); //Ending Table Row

for ($count_1 = $start_num;//intiéle expressie

$count_1 <= $end_num;//terminatie controle

$count_1++)//lus-einde expressie

{//open haakje

print("<tr><th>$count_1</th>"); //open table row and header and use the $count_1 variable

for ($count_2 = $start_num;//intiéle expressie

$count_2 <= $end_num;//terminatie controle

$count_2++)//lus-einde

{//open haakje

$result = $count_1 / $count_2; //Devision the 2 variables

print("<td>%.3f</td>", $result); //Nmbr of rows and tb data and closing tag.

}//sluit haakje

print("</tr>\n"); //end table row and newline

}?>

 

sorry about the comments I made, just for study.

 

Anyway, what might ther ebe something wrong in here?

 

mostly it says an error on the $result print line, I thaugh maby remove the " in the middle and add it to the end before the ) but then mine page goes weird with the numbers and therefore different result then in mine book.

But I copied every line treid to put a comment behind it for the study and still get the error.

Edited by kensha

Line 20 should be printf("<td>%.3f</td>", $result); //Nmbr of rows and tb data and closing tag.

 

You missed of the f on print. It stands for print format.

  • Author

wtb more eye detail,

 

I hope I will get used and will learn easier search to these kind of errors in the small syntaxes.

Oh well, just a student so I may make mistakes:).

 

Thanks for the help!

php often does a good job of telling you which line caused the problem. You'll get used to the error messages with time.

 

Then once you know what line caused the problem, going to the php documentation for the function which caused the error, print (http://php.net/manual/en/function.print.php), it shows that it takes 1 parameter, but in the code you were using 2. Then using experience, I could spot that in fact a very similar function which is listed on that page is called printf.

 

ps, feel free to up vote the post if it was helpful!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.