Trying to create a PHP function that only utilizes new instance of variable
I am trying to teach myself PHP. I have looked to find out how to make
this work.
I have an online portfolio that I am posting my weekly school assignments
and their grades when I receive them.
I currently have something that looks like this:
<?php
$page_title = "MATH203 | Journey to my Oasis";
$grade = "A = 185/185";
$course_title = "Applications of Discrete Mathematics";
$course_description = "Math. A fun four letter word. A lot of people have
issues with this subject. I like math. I am not proficient by any stretch
of the imagination, but I like it. It is challenging. Having this course
after programming, I believe, will allow me to think of it in the manner
in which it is intended. The professor is also teaches computer science.
This should be interesting.";
?>
<?php include("../includes/header.php");?>
<?php include("../includes/navigation.php");?>
<?php include("../includes/classannounce.php");?>
<div id="content">
<div id="content_container">
<div class="one_half">
<h3>Discussion Board Posts</h3>
<h4><ul>
<li>
<a href="url" target="_blank">Week 1</a>
Grade - A
</li>
<li>
<a href="url" target="_blank">Week 2</a>
Not yet graded
</li>
<!--
<li>
<a href="url" target="_blank">Week 3</a>
Grade - A
</li>
<li>
<a href="url" target="_blank">Week 5</a>
Grade - B-
</li>
-->
<li>All links open a new window</li>
</ul>
</h4>
</div>
</div><!--end content_container-->
</div><!--end content-->
'<?php include("../includes/footer.php");?>
</body>
What I would like to do is have a separate PHP file that I include in the
header PHP file so it goes everywhere with me just to cut down on the
amount of code.
Currently what I am doing is just hiding the html for the weeks that I
haven't come up to yet. I am using the original page as a template and
just changing it as I go. I am trying to incorporate PHP more so that I
can make changes easier and so that I can try to learn as much as I can. I
figure that by calling a function an populating it with the variables
needed I can cut down on the code needed and time required.
This separate file would have a function like:
<?php
function assignment()
{
$skydoc = '';
$week_no = '';
$grade_letter = '';
echo '<li>
<a href="',$skydoc,'" target="_blank">Week ',$week_no,'</a>
Grade - ',$grade_letter,'
</li>';
}
?>
I try calling the function an include the variables in it so that it will
fill in the appropriate sections.
assignment($skydoc = 'url', $week_no = '2', $grade_letter = '?')
I try that in the same file for testing purposes but all I get in HTML
when I try it on my server is this
<li>
<a href="" target="_blank">Week </a>
Grade -
</li>
Thank you in advance. Any more questions or need clarification, please let
me know.
No comments:
Post a Comment