Welcome! Log In Create A New Profile

Advanced

Topic 3B

Posted by Anonymous User 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Re: Topic 3B
March 27, 2006 01:52PM
Task completed.
avatar
Mac
Re: Topic 3B
March 27, 2006 02:24PM
libby

a { is required plenty places....

after
if (!$dir) {
after while {

before } else


Ignore the book -sort of. One can use if() without brackets, but normally if it is one line e.g.

if($this) echo "$that";

But once you start having ifs and whiles together, use brackets

if($this){ //start if

while { /start while
} //end while


} //end if
Re: Topic 3B
March 27, 2006 05:13PM
eventually got it working
the problem was that I have typed a semi-colon and a quotaion mark in the wrong order:
echo "<tr><td width='100%'><a href='$PHP_SELF? dir=$dir$item'>$item/</a></td></tr>\n;"

insted of

echo "<tr><td width='100%'><a href='$PHP_SELF? dir=$dir$item'>$item/</a></td></tr>\n";
avatar
Mac
Re: Topic 3B
March 27, 2006 06:59PM
Ok I missed that. It's not that I'm stupid smile
Just wasn't looking @ that.....

Simply because:

Errors related to brackets are NOT shown on the exact line. USE BRACKETS. Once you are sure your brackets are correct, errors shown are more precise to the exact line.

Ignore this post at your own peril.....
Re: Topic 3B
April 03, 2006 09:29AM
3B completed without too many problems. [/i]
Re: Topic 3B
April 03, 2006 09:34AM
3B completed without too many problems. [/i]

And that fine attention to detail gives you an idea of sort of problems I had! smile
Re: Topic 3B
April 06, 2006 09:04AM
Hi Mac

I have been trying to put those brackets in as you explained but they are causing parse errors and I can't figure out what you mean.

Here is my bracker version with a bracket after while and before else. The first bracket inserted after if(!$dir) is fine:

<?php
if(!$dir) {
$dir = ("./"winking smiley;
$dp = opendir($dir);
}
echo "<table border ='0' width = '100%' cellspacing = '0' cellpadding = '0'>\n";
while {
($filenames[] = readdir($dp));

sort($filenames);
for($i = 0; $i < count($filenames); $i++)
{
$item = $filenames[$i];

if (is_dir($item))
{
if($item != '.' && $item != '..'winking smiley

echo "<tr><td width='100%'><a href='$PHP_SELF? dir=$dir$item'>$item/</a></td></tr>\n";
}
}
else
echo "<tr><td width='100%'><a href='$dir/$item'>$item</a></td></tr>\n";
}
?>
</table>
avatar
Mac
Re: Topic 3B
April 07, 2006 09:33AM
The brackets in your code are not balanced out.

// Look at the comments after each bracket - unfortunately one cannot indent the code nicely in this forum, which you should do to help you balance brackets

<?php
/* This script creates a directory navigation script that allows users to view the contents of a directory as well as the contents of the files within the directory.*/

if(!$dir) { //start if dir
$dir = ("./"winking smiley;
$dp = opendir($dir);
} //end if dir
echo "<TABLE BORDER='0' WIDTH='100%' CELLSPACING='0' CELLPADDING='0'>\n";

while($filenames[] = readdir($dp));{ //start while

sort($filenames);
} //end while

for($i = 0; $i < count($filenames); $i++) { // start for loop

$item = $filenames[$i];

if(is_dir($item)) //start if(is_dir($item)

{
if($item != '.' && $item != '..'winking smiley

echo "<TR><TD WIDTH='100%'><A HREF='$PHP_SELF?dir=$dir$item'>$item/</A></TD></TR>\n";
}//end if(is_dir($item)

else{ //start if(is_dir($item) else

echo "<TR><TD WIDTH='100%'><A HREF='$dir/$item'>$item</A></TD></TR>\n";
}//end if(is_dir($item) else

} //end for loop
?>
</TABLE>
Re: Topic 3B
April 07, 2006 09:36AM
ok - this is how my code originally looked, but you advised I use additional brackets

QUOTE:
after while {

before } else

Your post of Date: March 27, 2006 02:24PM

This is what I don't understand
avatar
Mac
Re: Topic 3B
April 07, 2006 10:58AM
Your original code could not have had all the brackets as here above, since it generated errors, and you can't add more brackets than what you can use.

Look carefully and compare.

I am selling the ideas of brackets to help prevent errors and make the logic required to program easier.
Sorry, you do not have permission to post/reply in this forum.