Jump to content

Barand

Moderators
  • Posts

    24,429
  • Joined

  • Last visited

  • Days Won

    807

Posts posted by Barand

  1. I hadn't realised that you had already converted your finished column to the correct DATE type and format. Well done.

    SELECT CASE WHEN FINISHED = 0
    		THEN ''
    		ELSE DATE_FORMAT(FINISHED, '%d %M %Y') 
           END as FINISHED
    FROM games

     

  2. You have a similar problem in your original code when the finished date is blank

    echo date('d F Y', strtotime(''));         //--> 01 January 1970

    With STR_TO_DATE(), if the date string is blank you get 0000-00-00

    mysql> select finished
        ->      , str_to_date(finished, '%d-%m-%Y')
        -> from games;
    +------------+-----------------------------------+
    | finished   | str_to_date(finished, '%d-%m-%Y') |
    +------------+-----------------------------------+
    |            | 0000-00-00                        |
    | 20-12-2019 | 2019-12-20                        |
    +------------+-----------------------------------+

    I recommend formatting the date in the query instead of in php EG

    SELECT FINISHED
         , CASE WHEN FINISHED = ''
            THEN ''
            ELSE DATE_FORMAT(STR_TO_DATE(FINISHED, '%d-%m-%Y'), '%d %M %Y') 
            END as DATE_FINISHED
    FROM games;
    
    +------------+------------------+
    | FINISHED   | DATE_FINISHED    |
    +------------+------------------+
    |            |                  |
    | 20-12-2019 | 20 December 2019 |
    +------------+------------------+

    Then in the php code , just output $row['DATE_FINISHED']

  3. You can use the sql function str_to_date() to convert your dates to the correct format.

    In the mean time you can also use that in your query

    SELECT GAME, YR, PLATFORM, PUBLISHER, STR_TO_DATE(FINISHED, '%d-%m-%Y') as FINISHED 
    FROM games 
    WHERE COMPLETED='✔' 
    ORDER BY STR_TO_DATE(FINISHED, '%d-%m-%Y') DESC 
    LIMIT 10

     

  4. What format are you storing them in? You can get away with varchar so long as they are in" yyyy-mm-dd" format.

    31 minutes ago, Revolutsio said:

    WHERE COMPLETED='✔'

    Why the **** are you storing values as '✔' in your database?

  5. 17 hours ago, Barand said:

    Your data model should provide the teams and their players for any given date/fixture

    EG

    +---------------+                                
    |  school       |                                
    +---------------+                                
    | school_id     |---+                            
    | name          |   |    +--------------+                        
    +---------------+   |    |  team        |                                 +---------------+
                        |    +--------------+                                 |  player       |
                        |    | team_id      |--+                              +---------------+
                        |    | team_name    |  |                          +---| player_id     |
                        +---<| school_id    |  |                          |   | name          |
                             | sport_id     |  |                          |   | height        |
                             +--------------+  |                          |   | weight        |
                                               |                          |   | email         |
                                               |                          |   | dob           |
                                               |                          |   +---------------+
                                               |    +-----------------+   |
                                               |    | team_player     |   |
                                               |    +-----------------+   |
                                               |    | id              |   |
                                               +---<| team_id         |   |
                                                    | position        |   |
                                                    | player_id       |>--+
                                                    | played_from     |
                                                    | played_until    |
                                                    +-----------------+
    

     

  6. Forget the json then.

    This should give you the first 5 records in the format your C# is currently expecting

    $res = $conn->query("SELECT username
                              , level
                              , points
                              , killrate
                         FROM atable
                         ORDER BY points DESC
                         LIMIT 5;
                        ");
    $data = [];
    foreach ($res as $row) {
        $data[] = join('|', $row);
    }
    echo join('/', $data);

     

  7. Very confusing.

    • You say you have 2 entries in the database.
    • Then you say you want the top five entries in the database.
    • Your php code only echoes one entry

    Not surprised you're having problems.

    10 minutes ago, J450n said:

    Is there any other way of getting PHP form data into C#

    Don't know. This is a PHP forum.

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