Wainwright Posted February 28, 2007 Share Posted February 28, 2007 Ahoy there! I've got an odd question. I help run a political simulation, and the software we use to determine election results exports results to .csv, which is perfect. The problem is that I want to do a results display module, and I'm not sure how to make that work. The catch is that it either exports these results as a string ("Gold Party 2506 Green Party 1290 Blue Party 801"), which simply isn't much use to me in any context, or as hard-wired columns, for example: Constituency Electorate Gold Party Blue Party Green Party St. Mary Mead 21005 7008 12557 210 This is fine and well, but I'd like to display results ordered by vote total (I.E: "Blue Party: 12557, Gold Party: 7008, Green Party: 210") instead of in the order of these hard-wired columns. Is there any way I can make this happen? Quote Link to comment Share on other sites More sharing options...
fenway Posted February 28, 2007 Share Posted February 28, 2007 I'm not sure what you mean -- you can import this into a database table, then do whatever you want with it. Quote Link to comment Share on other sites More sharing options...
Wainwright Posted March 1, 2007 Author Share Posted March 1, 2007 Fair enough... take a look at the mockup I've got over here. You may have to visit the Advancer to kick-start it. Instead of displaying results by party, though, what I'd like to do is display results by current vote total. (I.E: If the Labour party has 500 votes and the Conservative party has 201, then Labour should display above the Conservatives in the per-constituency list.) The problem is that the numbers in question are in the database in the fashion I mocked up above... each party has a column for their vote counts. Is there any way to reconcile the two goals? Quote Link to comment Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 Databases can't sort across columns. Though you can kludge it. The easiest way to do this is to read the data into php and sort it there. If you REALLY want to do it in mysql, you can do something like SELECT Constituency, 'Electorate' as party, Electorate FROM votes UNION ALL SELECT Constituency, 'Gold Party' as party, `Gold Party` FROM votes ... and so on for each column. Then you can just sort by votes. Essentially you need to convert the columns into rows before you can do any kind of sorting in sql. Quote Link to comment 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.