Jump to content

COUNT number of times word appears in cells & list


leeandrew

Recommended Posts

On my site users can create a dream team of 11 players. Once they select a player for each position the player name is saved in a column with the position of the player e.g. `Centre Half` someone choose Jamie Carragher. So in cell 'Centre Half' "Jamie Carragher" is inserted.

 

Now i want to list how many times each player appears in users top11 players. i.e. Jamie Carragher is in 6 users top11's, so the number 6 appears in the list next to his name. And i want to create the top 10 most popular players.

 

1. Jamie Carragher (6) ... is in 6 users top11

2. Steven Gerrard (4) .. is in 4 users top11

3. Cristiano Ronaldo (4) ...

... etc.

 

I have been having problems count from different columns.

 

COUNT(*) FROM (gk,lb,cb1,cb2,rb,lm,cm1,cm2,rm,st1,st2) WHERE ?????

Link to comment
Share on other sites

Thats what i dont know how to do, i was listing every single entry (player) in a massive list with a SQL query next to each one, where i could write the players name in the WHERE part of the query, i dont know how to select each player and make it work for all.

Link to comment
Share on other sites

tablname is `pluserdata` auto incriment for user ID's is `id`, i have 11 columns which are the positions. named GK, LB, CB1, CB2 etc... each player has a profile where a user can click an option to assign the player to a certain position, so the player name is saved in the column of choice.

 

I am trying to count how many times a player name appears in columns GK, LB, CB1.... etc then create a toplist.

Link to comment
Share on other sites

Another page on my site uses this to create a toplist of best rank:

 

<?php


updateRanking();
$res = getRankingItems($listtype, $category);

$numrows=mysql_num_rows($res);
$records = array(array());
for ($i=1; $i<$numrows+1; $i++){
$records[$i]=mysql_fetch_array($res);
}
mysql_free_result($res);

if ($toplist > $numrows)	$listto=$numrows+1;
else $listto=$toplist+1;

$color[0]=$td_even;
$color[1]=$td_odd;
if ($toplist>$numrows) $toplist=$numrows;
?>

 

Then:

 

   <? 

for ($i=1; $i<$listto; $i++){
$bla=getmod($i,2);
?>

<P>
<b><? echo $i;?>.</b>
<? echo "<a href='/index.php?forceid=".$records[$i]['id']."'>
<b>".$records[$i]['name']."</b></a>";?>
</p>

<? }?>

 

Could i apply this code to create the toplist i want?

Link to comment
Share on other sites

tablname is `pluserdata` auto incriment for user ID's is `id`, i have 11 columns which are the positions. named GK, LB, CB1, CB2 etc... each player has a profile where a user can click an option to assign the player to a certain position, so the player name is saved in the column of choice.

 

I am trying to count how many times a player name appears in columns GK, LB, CB1.... etc then create a toplist.

 

So you are storing full text in the position fields?

That is poor method you should have a secondary table called Players that stores player data and use the foreign key of PlayerID in the "team" table to link it to each player

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.