SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Using Arrays

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using Arrays

    Hi Gang.

    I am after a bit of help with using an array. Firstly I will explain my problem as Im not sure if I should even be using arrays or not hehe

    Some of you may have seen my Flash Forums if you visit the Flash Forum on ere but anyway I am making the admin control panel and have come to the section where I am making the Prune Forums feature. Basically users can select to prune topics in a forum where the number of topic views is less than a number they specify. Lets say the user enters 20. My PHP script then selects out these forums by using this:

    PHP Code:
    $query "SELECT * FROM topics WHERE views<$views AND FID=".$fid
    where $views = 20 and $fid is the forum ID of the Forum they are pruning. So here is my first question. Do I need to store the ID for each topic in an array? What I needed to happen is once I have all the ID's it needs to delete all the topics from the topics table with the same ID's as the ones we are pruning and also delete the actual posts themselves in the POSTS table with the same Topic IDs as the prune.

    Does anyone have an example of how to use an array in this situation?

    Thanks

  2. #2
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup - array would be best for limiting the queries
    ...

    while($ret = mysql_fetch_array($query))
    {
    $id_array[] = $ret['topic_id'];
    }

    then maybe

    $remove_them = mysql_query("DELETE FROM `table` WHERE topic_id IN $id_array");

    semi guesssing with the IN as I've only used it with hardcoded params - eg WHERE x IN (7,12,16,19) - you might need to create a string and use that
    $id_string .= ', '.$ret['topic_id'];
    ...
    topic_id IN (" .substr($id_string,2). ")

    hope that helps
    teckis - that's news to me.


Bookmarks

Posting Permissions

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