RE: [PHP] Display Format

From: Date: Tue, 20 Feb 2001 19:10:04 +0000
Subject: RE: [PHP] Display Format
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-40789@lists.php.net to get a copy of this message
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: Website4S@aol.com [mailto:Website4S@aol.com] Sent: Tuesday, February 20, 2001 11:36 AM To: php-general@lists.php.net 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: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#40789) next »