maya_bglore Posted June 18, 2007 Share Posted June 18, 2007 Hello all, I would be getting the following entries from a user in the format, FirstName SurName RollNum Marks Linda Jones 345 78 Abby Gail 100 90 Mark Polo 234 67 The issue is to rearrange the list by sorting the first letter in surname.How do I go about this?? thanks in advance, Quote Link to comment https://forums.phpfreaks.com/topic/56073-sort-a-list-using-first-letter-of-surname/ Share on other sites More sharing options...
trq Posted June 18, 2007 Share Posted June 18, 2007 How exactly is this data being inputted by the user and where is it being stored (if at all)? Quote Link to comment https://forums.phpfreaks.com/topic/56073-sort-a-list-using-first-letter-of-surname/#findComment-276943 Share on other sites More sharing options...
maya_bglore Posted June 18, 2007 Author Share Posted June 18, 2007 Hi again, The data is being got from a form.My main problem is the way I can store the data. Once i extract all the first letters of the surname,i would be able 2 sort it.But how could i rearrange the list then?? Quote Link to comment https://forums.phpfreaks.com/topic/56073-sort-a-list-using-first-letter-of-surname/#findComment-276951 Share on other sites More sharing options...
GingerRobot Posted June 18, 2007 Share Posted June 18, 2007 Do you think we could see some of the code you have already? Even seeing the form might help us understand what you're trying to do a bit better. Quote Link to comment https://forums.phpfreaks.com/topic/56073-sort-a-list-using-first-letter-of-surname/#findComment-276953 Share on other sites More sharing options...
maya_bglore Posted June 18, 2007 Author Share Posted June 18, 2007 sorry..I havent yet done the form..but that is the requirement.User selects the number of entries he want to feed into the system.testboxes are then generated accordingly.All the details are entered and submitted.Once the sorting is done,the list needs to be displayed. Quote Link to comment https://forums.phpfreaks.com/topic/56073-sort-a-list-using-first-letter-of-surname/#findComment-276958 Share on other sites More sharing options...
GingerRobot Posted June 18, 2007 Share Posted June 18, 2007 Right, i would suggest that you name each of your form items as arrays: <input type="text" name="firstname[]" /> <input type="text" name="surname[]" /> You will then have arrays of the following: firstname, surname, roll number and marks. Use the function asort() to sort the surname array whilst maintaining the keys. You can then loop through the array and pull the data from the other arrays with the corresponding keys. Hope that makes some sense Quote Link to comment https://forums.phpfreaks.com/topic/56073-sort-a-list-using-first-letter-of-surname/#findComment-276965 Share on other sites More sharing options...
maya_bglore Posted June 18, 2007 Author Share Posted June 18, 2007 thankx,I got your concept.But I'm bit of a 'beginner' here...how do i generate the keys..bcos the arrays i.e firstname,surname etc are all indexed arrays..how can i make them associative arrays??? Quote Link to comment https://forums.phpfreaks.com/topic/56073-sort-a-list-using-first-letter-of-surname/#findComment-276967 Share on other sites More sharing options...
GingerRobot Posted June 18, 2007 Share Posted June 18, 2007 The idea is that they are indexed arrays. Quote Link to comment https://forums.phpfreaks.com/topic/56073-sort-a-list-using-first-letter-of-surname/#findComment-277088 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.