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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.