xkklxl Posted July 23, 2011 Share Posted July 23, 2011 Basically what I'm trying to do is list the top voted item for each letter. Here's what I have so far. <?php $filename = 'db.txt'; $handle = fopen($filename, 'r'); $data = fread($handle, filesize($filename)); $rows = explode("\n", $data); $top = array(); $top2 = array(); for($x = 0; $x < count($rows); $x++) { $line = explode("\t", $rows[$x]); for($y = 0; $y < count($line); $y++) $top[$x][$y] = $line[$y]; } for($i = 0; $i < count($top[0]); $i++) { for($j = 0; $j < count($top); $j++) { $top2[$i][] = $top[$j][$i]; } } ?> db.txt: voter a b c d person 1 apple banana cantaloupe date person 2 asparagus broccoli carrot dandelion person 3 apple brownie chocolate danish person 4 apple broccoli carrot date What I want the output to be is for each letter in html or w/e: <?php echo '<table> <tr><td><u>a</u></td></tr> <tr><td>apple - 3 votes</td></tr> <tr><td>asparagus - 1 votes</td></tr> </table>'; ?> I cannot think of a way to do this at all. I tried fooling around with array_count_values but it loses the key, and I can't think of a way to call it without knowing what people voted for. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/242676-another-logic-probelm/ Share on other sites More sharing options...
trq Posted July 23, 2011 Share Posted July 23, 2011 Is there a particular reason your using a text file instead of a database? Your making allot more work for yourself. Quote Link to comment https://forums.phpfreaks.com/topic/242676-another-logic-probelm/#findComment-1246430 Share on other sites More sharing options...
xkklxl Posted July 23, 2011 Author Share Posted July 23, 2011 It's because I'm getting the file from a Google Docs spread sheet. The spreadsheet has a lot more values. I'm just using this tiny file as an example. Quote Link to comment https://forums.phpfreaks.com/topic/242676-another-logic-probelm/#findComment-1246437 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.