The MU forums have moved to WordPress.org

need a tutorial on php arrays (7 posts)

  1. drmike
    Member
    Posted 17 years ago #

    greets:

    Can anyone point me at a very basic tutorial for PHP arrays? I loaned out my dummy book. :(

    The good news is though I'm working on a way to see who's got the most views within a month. Just need a way to save the data. :)

    thanks,
    -drmike

  2. andrewbillits
    Member
    Posted 17 years ago #

    This has helped me in the past.

    Edit: I just noticed you asked for a "basic" tutorial. The above is not basic but it should answer any questions you might have. ;)

  3. drmike
    Member
    Posted 17 years ago #

    Thnaks.

    Can you please hit this:

    http://daria.be/fix.txt

    and make any suggestions? You have to add in the database information of course.

    Thanks,
    -drmike

  4. andrewbillits
    Member
    Posted 17 years ago #

    Sure thing, i'm on my way out the door but i'll have a look when I get back. :)

  5. andrewbillits
    Member
    Posted 17 years ago #

    Hmm, this has serious plugin potential. You could easily turn it into a plugin that automatically creates an archive of the top blogs for each month/week/day.

    Also, if you're just looking for the blog with the highest view count and don't need the top five or ten blogs you could always use the poor mans technique. Basically you just have two variables like $top_view_count = 0 and $top_blog. You then just loop through each record and if the view count is higher than $top_view_count you load that variable and $top_blog with the new data.

    I've used this technique before when I didn't want the hassle of an array.

  6. drmike
    Member
    Posted 17 years ago #

    Agreed but I want the array. I'm looking into this as a replacement for the "Most active" list of blogs we discussed a few days ago.

    Before I add my own code into our WPMu code, I do is as a seperate file to test it. That way I can work on the production server without causing errors.

  7. lunabyte
    Member
    Posted 17 years ago #

    Interesting.

    You could set a key in site_options (note the global one), with the array in it.

    So then you could have

    get_site_option('dm_topweek')
    or topday, top month, etc.

    Then have a key within it that has the last time it was generated, and only do the actual db calls for pulling fresh results every so often. Daily, weekly, monthly.

    You can store everything you need in the array, like total post count, url, the site's admin's displayed name, whatever.

    I did something similar, in terms of an array, with a featured blogger plugin I'm putting on my site. Works pretty nifty, and I can set it (although the value is hard coded since it's for personal use) to refresh and make a new featured blogger however often I'd like. Every hour, 5 minutes, week, month, whatever.

About this Topic