hcamelion
08-03-2007, 09:50 PM
I have a table similar to this:
manufacturers_name manufacturers_sort
John Doe | Doe, John
The Cream Puffs | Cream Puffs The
Jason Stark |
Joey Sparks | Sparks Joey
Sarah Banks |
I Need it to sort like this:
C:
The Cream Puffs
D:
John Doe
J:
Jason Stark
S:
Sara Banks
Joey Sparks
Basically it sorts by the sort name but if that is null it sorts by the display name. I am using this statement now:
select display_name from manufacturers order by manufacturers_sort, manufacturers_name
while ($list = mysql_fetch_array($result)) {
if($list['manufacturers_sort'] != "")
$letter = strtoupper(substr($list['manufacturers_sort'],0,1));
else
$letter = strtoupper(substr($list['manufacturers_name'],0,1));
if ($letter != $prev_row) {
$output .= $letter;
} // end if
$output .= $list['manufacturers_name'];
..............................
.............
......
..
This is puts any entries where the sort name is not null at the end of the page like this:
J:
Jason Stark
S:
Sarah Banks
C:
The Cream Puffs
D:
John Doe
S:
Joey Sparks
Anyone know how I can accomplish what I want to do.
manufacturers_name manufacturers_sort
John Doe | Doe, John
The Cream Puffs | Cream Puffs The
Jason Stark |
Joey Sparks | Sparks Joey
Sarah Banks |
I Need it to sort like this:
C:
The Cream Puffs
D:
John Doe
J:
Jason Stark
S:
Sara Banks
Joey Sparks
Basically it sorts by the sort name but if that is null it sorts by the display name. I am using this statement now:
select display_name from manufacturers order by manufacturers_sort, manufacturers_name
while ($list = mysql_fetch_array($result)) {
if($list['manufacturers_sort'] != "")
$letter = strtoupper(substr($list['manufacturers_sort'],0,1));
else
$letter = strtoupper(substr($list['manufacturers_name'],0,1));
if ($letter != $prev_row) {
$output .= $letter;
} // end if
$output .= $list['manufacturers_name'];
..............................
.............
......
..
This is puts any entries where the sort name is not null at the end of the page like this:
J:
Jason Stark
S:
Sarah Banks
C:
The Cream Puffs
D:
John Doe
S:
Joey Sparks
Anyone know how I can accomplish what I want to do.