View Full Version : PHP -> MySQL = how to count the most

02-20-2003, 02:30 PM
I'm compleate newbie, so, sorry, if it's stupid question. And sorry, if this was asked before, I just dont know what should I search for...:(

So, here what I have:
I set database, that has 1 table with 4 fields: ID, Date, User, Images.

so, for each User asigned unic ID, and in Images field stores User's images names separated by space.
so, it would looks like this:

k324lkjl234hklj243 | 3432584 | V@no | 2343 dog cat anotherimage sunset
each user can have same images ( they chose from the site for them selfs), so, what I cant figure out, how can I count the most popular images, the most users pick for them selves.
can someone help me with that?

P.S. the closed idea I got, is create an array (i.e. $images = array(); ) read each user's images into that array, and then count each image name...but still not sure how to do this eaither....:confused:

Please, if someone know how can I do this, let me know.


02-21-2003, 02:45 AM
the way you have the images stored .. i.e. a space seperated field in the DB , makes it a little difficult without doing as you suggest - grab the fields explode each one into an array & then start counting...

whilst thats possible its a slow process & one you would not want to do very often.

My suggestion would be to actually look at the script where a user chooses an image , and at that point log their choice into another table which just has the fields 'image_name' and 'count' which will be much easier to reference !

anyway - you could try something like this...

$query=mysql_query("SELECT $fieldname FROM $table");
$bits=explode(' ',$yaks[0]);
foreach($bits as $bobs){