Jump to content

akitchin

Staff Alumni
  • Posts

    2,515
  • Joined

  • Last visited

    Never

Posts posted by akitchin

  1. I would simply associate each product with all four levels of groupings ass applicable. So, let's assume you have four tables for each level:

     

    Section 1 (e.g. Furniture)

    Section 2 (e.g. Living Room)

    Section 3 (e.g. Sofas)

    Section 4 (e.g. Sleepers)

     

    Every lower section will have a parent ID field that relates it to the next higher level (i.e. Sofas will be associated with Living Room). So, you don't have to have child records for each possible parent record.

     

    Then, for your products, have four separate fields to identify the relationship between the product and all four levels of sections. If you have a product that is related to records at sections 1 & 2, then the fields for sections 3 & 4 will remain NULL.

     

    So, if you need to find all products related to Furniture, just query all products where the ID in the section1 field is the same as the ID for furniture.

     

    Now, if you need to relate products to multiple values int eh same section it gets more complicated, But, you didn't state thar requirement.

     

    the problem with this structure is, what if you want to suddenly associate a product with five sections? you'd have to add a column, and if the database is designed properly, you should never need to change the structure itself after starting to use it.

  2. i'm aware of what you're trying to do; it just doesn't seem you're actually interested in learning how, you appear to just want a chunk you can copy/paste. and frankly, that doesn't do anyone any good, because if it suddenly needs to be changed, you'll just come back instead of understanding how to change it yourself. teach a man to fish and all that.

     

    anyway, in the interest of solving this thread, you need (as i mentioned) an if-else statement:

     

    if (isset($_GET['id']))
    {
      $where_clause = "WHERE ID='{$_GET['id']}'";
    }
    
    if (isset($_GET['county']))
    {
      if (empty($where_clause))
        $where_clause = "WHERE County='{$_GET['county']}'";
      else
        $where_clause .= " AND County='{$_GET['id']}'";
    }
    
    echo $where_clause;

     

    now here's where your homework is: you need to find out how to get $where_clause in the correct spot to make the query work correctly. it's worth mentioning that this isn't validating the input at all, leaving your script extremely vulnerable to attacks.

  3. i would guess that with this setup, the most straightforward method would be with PHP, given the amount of control structures required. have you investigated the preorder tree traversal structure for your data? MySQL has a good article on it. it makes querying for the data you're after a much simpler affair, but of course it requires that you restructure your model.

     

    i'm ready to be chastised for saying this, but i think for using the old parent_id structure, using either PHP or SQL would have similar performance if you simply manage your database connections and resultsets wisely.

  4. well, you're already grabbing the lastexport column's value in the query you use to get the markets in the first place:

     

    SELECT * FROM markets WHERE export=1 ORDER BY market

     

    unless i'm mistaken about where that column resides.

  5. yes - that's what your whole parenthesized portion of the query is: short-hand notation for an if-else conditional block. if you don't understand what if/else statements are, you need to read the PHP manual section on Control Structures. if you don't understand those, you can't possibly hope to string together a proper query based on URL variables.

  6. ... no. you should be writing each query out, on its own, without any HTML formatting or semicolons in the string, and running it as an individual query. right now you're trying to feed it a string that looks like this:

     

    QUERY HERE;<br />QUERY HERE;<br />QUERY HERE;<br />

     

    you need to be giving it JUST the:

     

    QUERY HERE

     

    portion.

     

    EDIT: beaten to the punch, but this has a bit more info.

  7. if you want greater than single-day resolution in the operations, you will need to change the user's registration date columns to a DATETIME format. in order to try to avoid orphaning, you may want to add a padding (say, maybe 5 minutes' worth) for the time it takes to actually run the excel export as well.

  8. actually, you would add it at the end - you don't want to update the lastexported column until the export has actually completed (which isn't until after those two closing braces). you may also want to adjust the query to only update the lastexported column for the markets with an export value of 1.

     

    don't forget to adjust the SELECT query for the users to include the lastexported value - remember, you only want to select users that have registered since the date/time in that column.

  9. you should be able to store the resultset within an array regardless of how many records are in the set:

     

    $master_data_set = array();
    while ($myrow1 = mysql_fetch_array($result1))
      $master_data_set[] = $myrow1;

     

    then, when you need to go through the info, rather than running the query and using a while() loop, simply run a foreach() loop on $master_data_set. this saves you from having to query the database and have it return the same resultset.

  10. i take it your definition of "new" is simply "new registrations since last export"? if that's the case, then your best bet is indeed to have a `last_exported` column in your markets table with the format DATETIME and update it each time that market's users have been exported. then it's simply a matter of selecting WHERE `date_registered` > `last_exported`.

     

    i'm not sure how you intend to run these exports, or what the `export` column's specific significance is (ie. does it mean "export on the next script run," or "export everytime the script runs").

  11. one option would be to add to the pattern to match any number of non-end-brace characters so that it matches up until the end of the braced section:

     

    '/((?:{module title\="((?:[a-zA-Z0-9_ ]*))" action\="((?:[a-zA-Z0-9_ ]*))"[^}]*\}))/i'

     

    i'm not a regex guru, so you might need to escape that end brace in the character set i've added.

     

    EDIT: wasn't paying close enough attention. see JAY's post.

  12. look in the MySQL manual at the DATE_FORMAT() function, which does exactly what you're asking. a script with that few lines is not a problem to paste here, and is easier to read here than having to jump to another link. please post in the forum for small scripts like this in future.

  13. your conditions are incorrectly written:

     

    if ($sort=0)

     

    you're evaluating whether $sort=0 is true. it always will be, since you're just checking whether $sort can be successfully assigned a value of 0. if you want to COMPARE the values, you need to use two equal signs. read up in the PHP manual on operators.

×
×
  • 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.