Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Thanked 0 Times in 0 Posts

    Question PHP -> MySQL = how to count the most

    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:
    PHP Code:
    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....

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


  • #2
    Super Moderator
    Join Date
    May 2002
    Perth Australia
    Thanked 101 Times in 99 Posts
    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...

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


    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts