Page 1 of 1

Categorize results A-Z

Posted: Sat Nov 05, 2005 1:50 pm
by efsguitar
Hello,

I am parsing and returning results from an xml doc and calling it ($name)
Ultimately I want to return all properties A-Z and print out a header for each.
I also need to start a new row every 4 records returned!

Similar to this: http://www.topsail-realty.com/pages/alp ... _list.html

I tried using Xpath on an xsl stylesheet but not being able to reassign variables stumped me.

I would prefer to do it in php anyways.
Below is one poor method I came up with. It works but is not very resourceful. I am sure there is a better way to do this, than to repeat If statement for each letter. I have been paging through google for days, Just need a little direction!

Code: Select all

$drawheader= "open";

foreach ($prop as $name) {
  
  $header= substr($name, 0,1);

if ($header == "A") {

if ($drawheader == "open"){
$drawheader= "close";
echo "<tr class='tdcolorhead'><td colspan='4'>$header</td><tr>";
}/* Close if drawheader*/

$countbreak++ ;
if ($countbreak == "4"){
echo "</tr><tr>";
$countbreak = "0";}/* Close if count break*/
 echo "<td><a href='http://secure.instantsoftwareonline.com/stayUSA/Property.aspx?coid=0008&propid=$propid'>$name</a> </td>";

}/* Close if header*/
}/* Close loop*/

If you think this would be the only efficient way, please let me know.
Any help would be appreciated!

thanks, Nick

Posted: Sat Nov 05, 2005 4:07 pm
by s.dot

Code: Select all

$array = array("a","b","c","d","e","f","g","h","i","j","k","l","m");

foreach($array AS $letter)
{
   // do your thang
}

Posted: Sat Nov 05, 2005 4:29 pm
by josh

Code: Select all

for ($x=ord("a"); $x<=ord("z"); $x++) {
$current_letter=chr($x);
}