Jump to content

Recommended Posts

Ok. So I.m trying to learn the language.

 

I have this program:

<?php
require_once("fillarray.inc");
?>


<html>
<head>
<title>PHP Class Lesson 2 - AJ</title>
</head>
<body>
<h1>The Circumference of a Circle</h1>
<br>
<table border="1">
    <thead>
        <tr> Circle Number:</tr>
        <tr> Diamater</tr>
        <tr> Circumference</tr>
        <tr> radius</tr>
        <tr> Area</tr>
    </thead>
<?php
foreach($arr as $diameter){
    echo ("<td>");
    echo("<tr align=\"center\"> 1 </tr>");
    echo ("<tr> $diamater </tr>");
    $circumference = $diameter * M_PI;
    echo ("<tr> $circumference </tr>");
    $radius = $diameter/2;
    echo ("<tr> $radius </tr>");
    $area = pow($radius,2)*M_PI;
    echo ("<tr> $area </tr>");
    echo ("</td>");
}
?>
</table>
</body>
</html>

 

and in fillarray.inc I have:

 


$totalnum = rand(0,25);
$arr = array();
for($i=0;i<$totalnum;i++){
$arr[$i] = rand(1,100);
}

 

But when I run it, this is the display i get:

 

$totalnum = rand(0,25); $arr = array(); for($i=0;i<$totalnum;i++){ $arr[$i] = rand(1,100); }

The Circumference of a Circle

 

Circle Number: Diamater Circumference radius Area

 

Any help on whats going on?

Link to comment
https://forums.phpfreaks.com/topic/259886-problem-with-include/
Share on other sites

The php code in the file you are including must be valid php code, with any opening and closing php tags (you can include anything, like HTML, and php must be told where the php code starts and ends in every file.)

 

Also, use .php for the extension of the file. It does not matter in this case, but if you start putting database connection credentials in an included file, if the file extension is not .php, someone can browse to the file and get the raw database connection credentials.

when I add the php tags, i get this error:

 

Parse error: syntax error, unexpected T_INC, expecting ')' in /www/99k.org/t/h/e/thegoodvibe/htdocs/Class/Lesson3/fillarray.inc on line 4

 

if I look at my file, line 4 is:

$arr = array();

 

and i cant figure out why it tells me that

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.