I have a table where the ids are in the pattern,
1.a
1.a.2
1.a.3
1.a.4.5
2.a
2.b.a
2.b.a
2.b.c
I want all the rows which has highest in that branch.
In the above example, i need
1.a.4.5
2.b.a
2.b.a
2.b.c
getting ids from group of ids
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I need the highest branch ids
1.a - 2
1.a.2 - 3
1.a.3 - 3
1.a.4.5 - 4
2.a - 2
2.b.a - 3
2.b.a - 3
2.b.c - 3
In first case, i need, 1.a.4.5 as it is the highest(4) number of characters
in the second case i need, 2.b.a, 2.b.a, 2.b.c as they are having the highest(3) number of characters
1.a - 2
1.a.2 - 3
1.a.3 - 3
1.a.4.5 - 4
2.a - 2
2.b.a - 3
2.b.a - 3
2.b.c - 3
In first case, i need, 1.a.4.5 as it is the highest(4) number of characters
in the second case i need, 2.b.a, 2.b.a, 2.b.c as they are having the highest(3) number of characters
Last edited by thatsme on Sat Dec 15, 2007 2:18 am, edited 1 time in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
i am trying to use PHP.
I am trying to get all elements and then comparing their stringlength. Got struct here 
Code: Select all
$getOccupation_RES = mysql_query("SELECT SUBSTRING(element_id, 1,1) AS first_character, `element_id`,`element_name` FROM tbl_element");
while($getOccupation_RET = mysql_fetch_array($getOccupation_RES))
{
$first_character[] = $getOccupation_RET['first_character'];
$element[] = $getOccupation_RET['element_id'];
}
for($i=0; $i<=count($first_character); $i++)
{
$highest = $element_id[$i];
if(strlen($element[$i]) >= $highest)
$highest = $element[$i];
// echo "FCharacter : $first_character[$i] Length". strlen($element[$i]);
// echo '<br/>';
}
echo $highest;
}