Jump to content

Another logic probelm...


xkklxl

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/242676-another-logic-probelm/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.