Jump to content

AyKay47

Members
  • Posts

    3,281
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by AyKay47

  1. Well, scootstah broadly answered your last inquiry:

     

    I would be curious to know how PHPFreaks does things too..

     

    PHPFreaks uses SMF, if you research SMF you will understand how this website is set up.

     

    But to your questions, this kind of database set up is more of a common sense ordeal than anything else really.

    The normalization here depends on the private message logic (what features you want to have incorporated in the PM functionality.)

    I see that you have already thought about the features and have laid them out, this is good.

     

    Private Message:
    - id
    - sender_id
    - recipient_id
    - subject
    - body
    - sent_on
    - new_message_status (recipient)
    - recipient_read_status (sender)
    - sender_deleted_status (sender)
    - recipient_deleted_status (recipient)
    - recipient_responded_status (sender)(recipient)

     

    You never want to have too many fields in a single table that aren't necessary for the core functionality and can increase dependency.

    In your case, given the data in this thread, I would break this into 2 (or possibly more) tables.

    I would have the core private message data in one table:

     

    - id
    - sender_id
    - recipient_id
    - subject
    - body
    - sent_on

     

    The above data is the essential data needed for a message, the other data is simply nice features that are not needed in the main table. so the second table:

     

    - new_message_status (recipient)
    - recipient_read_status (sender)
    - sender_deleted_status (sender)
    - recipient_deleted_status (recipient)
    - recipient_responded_status (sender)(recipient)

     

    Of course, there would be a few relations needed to link the first and second tables:

    1. the message id

    2. the recipient id

    3. the sender id

     

    The "message id" would be the primary key (pk) and would link to the `id` field in the first table.

    The other two fields would be foreign keys (fk's) linking to the recipient and sender id's respectfully.

    I might even break the second table into smaller tables separating them by each individual functionality to simplify things even further, but I will leave this up to you to decide.

  2. And what about the SQL statement?

    How should that be modified?

     

    It doesn't need to be, you will generate the full name using PHP, something like what dragon_sa suggested.

    the code will then be:

     

    $firstname = $_POST['firstname'];
    $middleinitial= $_POST['middleinitial'];
    $lastname= $_POST['lastname'];
    $full_name = "$firstname $middleinitial $lastname";
    $sql = "INSERT INTO myTable ( FULL_NAME ) VALUES ( $full_name )";
    $result = mysql_query($sql);   
    

     

    But typically, for greater database flexibility, you would separate each part of the name into 3 separate fields.

    So you would have `first_name`, `middle_initial` and `last_name` fields.

    Then when grabbing the data vie select statement, use CONCAT_WS() to alias all three columns into a  full_name result.

  3. 1. each language should be kept separate and you should avoid intermingling them (IMO).

    2. My advice would be to run any sort of validation using PHP and not JavaScript, as JavaScript can simply be disabled.

    3. I normally always link to an external .js page which holds all of the JavaScript code, to keep it away from the design and PHP business layers.

  4. Does $_SESSION['returnToPage'] simply hold the http_referer?

     

    A switch is the way to go for this I believe, to compare multiple values against the session value.

    darkfreaks was close, however the switch syntax is a little off:

     

    $returnToPage = null;
    switch($_SESSION['returnToPage'])
    {
        case 'members/my_account.php':
            $returnToPage = '/index.php';
            break;
        default:
            $returnToPage = $_SESSION['returnToPage'];
            break;
    }

     

    You will add new cases for each referer that you do not want to set $returnToPage to the session value.

    The default condition will trigger if the session value does not equal any case values.

    You can (should?) add the switch into an if statement checking for the session being set first.

  5. If there are multiple text fields that a user can specify an order, than using an array name is fine, and the foreach is fine.

    However you certainly do not want a foreach loop inside of a while loop, and running queries each iteration at that.

    This can be done with one query using only the foreach loop.

     

    foreach($_POST['order_by'] as $order_by)
    {
        $sql = "UPDATE source_subject
        SET order_by = '$order_by'
        WHERE subject_id = '$subject_id'
        AND source_id IN (select source_id from table)"; //replace 'table' with whatever table the column is supposed     to come from. 
    }

  6. Thanks to all who voted - we ended up with 90% saying yes... which I'd say is a pretty good indication we want some friendly competition going around here. I'm going to start planning & more discussions with the staff and release more information when we're ready (hopefully soon!)

    Awesome, this should be cool..

  7. I'm going to take a stab at this one, not 100% sure.

    I believe the error is happening because the object that you are creating inside of the function is not available outside of its scope.

    Try passing the form object into the function via is argument list.

  8. Is this switch within a class? If so, you are running into a scope issue. You'll have to mark the variable as Global within the class.

    http://php.net/manual/en/language.variables.scope.php

     

    globals should never be used.

    They can cause variable pollution and completely break the encapsulation of a class/function.

    If you need access to a variable in the global scope, pass it through the argument list.

    I still do not understand the issue.

  9. You are not using a join you are using a union.

    Do you know what you are actually doing by setting @x:= to a field? Because you immediately overwrite the value that you set.

    If you are not sure if one of these values will return a result set, use a join or subquery.

     

    select distinct `type 1 users` as type_1,
    count(id) as count,
    (select distinct `type 2 users` from users where type = 2) as type_2
    where type = 1; 

     

    *This query is untested, may need tweaked*

  10. $a = array(01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11);
    $a_w = array_walk($a, function($v,$k) use(&$a) {
    ltrim($v, 0);
    });
    if($a_w)
    {
    print_r($a);
    }

     

    results:

     

    Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 0 [8] => 0 [9] => 10 [10] => 11 )

     

    This is pseudo code, I'm sure a better way exists, but I'm having a brain fart.

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