In Reply to:
>Firstly is there any way I can sort these in alphabetical order??
>
>More importantly is there any way of formatting them so they display
>
>Paul Mark
>Tom Ade
>
>So they are in two columns in a table rather than one??
>
>Thanks for any help
>Ade


<?
$filename = "category/category.inc";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
$content = explode (",", $contents);

// Look at the array functions in the manual.  Php has no problem sorting
arrays
// http://www.php.net/manual/en/function.sort.php

sort($content);

// I have the habit of taking function calls out of loops
// The loop does not need to call function every iteration
$array_count = count($content);

for ($a=0;$a<$array_count;$a++){

echo "<TR><TD><A HREF='showcat.php?Cat=".$content[$a]."'>";
echo str_replace(" ","",strtolower($content[$a]));
echo "</A></TD>";

$a++;

echo "<TD><A HREF='showcat.php?Cat=".$content[$a]."'>";
echo str_replace(" ","",strtolower($content[$a]));
echo "</A></TD></TR>";

// There is an article on zend.com that clearly states that the
// below is incorrect usage of printf
// http://www.zend.com/zend/art/mistake.php
// printf("<TR><TD><A HREF='showcat.php?Cat=%s'>%s</A></TD></TR>",
str_replace("
// ","",strtolower($content[$a])), $content[$a]);
}

?>

I can't test this, but it should give you some idea of what to do next.

Robert Zwink
http://zwink.levitate.org




-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 20, 2001 11:36 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Display Format


Hi,

I`m using the following code to display the contents of a file.....

<?
$filename = "category/category.inc";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
$content = explode (",", $contents);

for ($a=0;$a<count($content);$a++){
printf("<TR><TD><A HREF='showcat.php?Cat=%s'>%s</A></TD></TR>",
str_replace("
","",strtolower($content[$a])), $content[$a]);
}

?>

It is working fine at the moment but I want to try and be a tad more
ambitious, say for example the category.inc contains the following:

Paul,Mark,Tom,Ade

My code will display the results like so...

(Obviously with my HTML in there too)
Paul
Mark
Tom
Ade

Firstly is there any way I can sort these in alphabetical order??

More importantly is there any way of formatting them so they display

Paul Mark
Tom Ade

So they are in two columns in a table rather than one??

Thanks for any help
Ade

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to