Jump to content

Barand

Moderators
  • Posts

    24,423
  • Joined

  • Last visited

  • Days Won

    806

Posts posted by Barand

  1. From the php manual...

    Quote

    Troubleshooting

    The most common problem with installing OCI8 is not having the Oracle environment correctly set. This typically appears as a problem using oci_connect() or oci_pconnect(). The error may be a PHP error such as Call to undefined function oci_connect(), an Oracle error such as ORA-12705, or even an Apache crash. Check the Apache log files for startup errors and see the sections above to resolve this problem.

    While network errors like ORA-12154 or ORA-12514 indicate an Oracle network naming or configuration issue, the root cause may be because the PHP environment is incorrectly set up and Oracle libraries are unable to locate the tnsnames.ora configuration file.

     

  2. Then your "MyPHPScript.php" should

    1. retrieve the inputs from the $_GET array
    2. Send the email
    3. Update the database
    4. Use http_build_query() to rebuild the querystring then use header("Location: NEW URL WITH QUERYSTRING) to send to remote page.
    19 minutes ago, InternetGuy said:

    If I can just see such a script

     = euphemism for "if someone will write it for me (for free)", which is probably why you can't get the answer you really want.

  3. Seriously!? You let anyone delete any record from any table just by putting values in a query string?

    http://.../delete.php?target=user&username=admin

    Brownie points for trying to use "prepare()" but your usage is wrong. The $id variable should not be in the query (that's the whole point of prepared statements). Use a placeholder instead and pass the id as a parameter

    $stmt = $pdo->prepare("DELETE FROM SOME_DATABASE.$table WHERE $idType = ?");
    $status = $stmt->execute( [$id] );

     

  4. I assume you've had a go at it yourself by now. Here's my effort...

    <?php
    $data = [];
    for ($r=0; $r<4; $r++) {
        for ($c=0; $c<4; $c++) {
            $data[$r][$c] = rand(0,1);
        }
    }
    
    $rowcounts = $colcounts = [];
    for ($r=0; $r<4; $r++) {
        $rowcounts[$r] = count(array_keys($data[$r], 1));
    }
    for ($c=0; $c<4; $c++) {
        $colcounts[$c] = count(array_keys(array_column($data,$c), 1));
    }
    
    $rmax = max($rowcounts);
    $cmax = max($colcounts);
    $rcmax = max($rmax, $cmax);
    
    $hirows = array_keys($rowcounts, $rcmax);
    $hicols = array_keys($colcounts, $rcmax);
    
    echo "<table border='1' style='border-collapse:collapse'>\n";
    for ($r=0; $r<4; $r++) {
        echo "<tr>";
        for ($c=0; $c<4; $c++) {
            $hilite = (in_array($r, $hirows) || in_array($c, $hicols)) ? 'class="max"' : '';
            echo "<td $hilite>&nbsp;{$data[$r][$c]}&nbsp;</td>";
        }
        echo "</tr>\n";
    }
    echo "</table>\n";   
    ?>

    image.png.5808b5d66225aedee66ff4163bb0e972.png

    • Like 1
  5. I store prices as decimal EG

    +-------------+------------------+------+-----+----------------------+--------------------------------+
    | Field       | Type             | Null | Key | Default              | Extra                          |
    +-------------+------------------+------+-----+----------------------+--------------------------------+
    | prod_id     | int(11)          | NO   | PRI | NULL                 | auto_increment                 |
    | description | varchar(50)      | YES  |     | NULL                 |                                |
    | price       | decimal(10,2)    | YES  |     | NULL                 |                                |
    +-------------+------------------+------+-----+----------------------+--------------------------------+

     

    Query example...

    TABLE: product                                     TABLE: cart
    +---------+-------------+--------+                 +----+---------+------+
    | prod_id | description | price  |                 | id | prod_id | qty  |
    +---------+-------------+--------+                 +----+---------+------+
    |       1 | Product AZ  |  49.99 |                 |  1 |       1 |    2 |
    |       2 | Product B   |  29.99 |                 |  2 |       3 |    5 |
    |       3 | Product C   |   9.99 |                 |  3 |       7 |    1 |
    |       4 | Product D   |  22.99 |                 |  4 |       6 |    2 |
    |       5 | Product E   |  29.99 |                 +----+---------+------+
    |       6 | Product F   |  19.99 |
    |       7 | Product G   | 129.99 |
    |       8 | Product H   |  99.99 |
    |       9 | Product I   |  74.99 |
    |      10 | Product J   |  69.99 |
    +---------+-------------+--------+
    
    SELECT p.prod_id
         , p.description
         , p.price
         , c.qty
         , p.price * c.qty as total
    FROM test_product p
             JOIN
         test_cart c USING (prod_id);
         
    +---------+-------------+--------+------+--------+
    | prod_id | description | price  | qty  | total  |
    +---------+-------------+--------+------+--------+
    |       1 | Product AZ  |  49.99 |    2 |  99.98 |
    |       3 | Product C   |   9.99 |    5 |  49.95 |
    |       7 | Product G   | 129.99 |    1 | 129.99 |
    |       6 | Product F   |  19.99 |    2 |  39.98 |
    +---------+-------------+--------+------+--------+

     

  6. 30 minutes ago, makamo66 said:

    I'm doing something like that

    Doesn't sound like you are doing anything like that.

    In my code, if the product isn't in the cart it adds it, with the quantity. If the product is already in the cart it updates the quantity.

    No removals required (unless, of course, the user wants to cancel)

  7. 2 hours ago, webchambers1 said:

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp

    Really!?

    Hard to believe that, with your markup, you are actually using css files.

  8. If you want always to go back 2 years, then a slight modification to my above code

    <?php
    // CREATE A RANGE OF MONTHS  //
        $dt1 = new DateTime('-2 years');
        $dt2 = new DateTime();
        $dp = new DatePeriod($dt1, new DateInterval('P1M'), $dt2);
    
    // STARTING FRIDAY  //
        $fri = clone $dt1;
        $fri->modify('last friday of previous month');
    
    // LOOP THROUGH THE MONTHS    //
    // AND STORE IN months ARRAY  //
        $months = [];
        foreach ($dp as $d) {
            $key = $d->format('Y-m');
            $months[$key]['start'] = $fri->modify('+1 days')->format('Y-m-d');    // add 1 day to previous friday for start date
            $fri = $d->modify('last friday of this month');                       // get last friday of the month for end date
            $months[$key]['end'] = $fri->format('Y-m-d');
        }
    
    // CHECK THE RESULTS  //
        echo '<pre>';
        printf("<b>%-14s%s</b>\n", 'Month', 'Fiscal month');
        printf("<b>%-10s%10s &mdash; %-10s</b>\n", '', 'Saturday', 'Friday');
        print("--------+------------------------\n");
        foreach ($months as $k => $m) {
            printf("%-7s | %-10s &mdash; %-10s\n", $k, $m['start'], $m['end']);
        }
        print("--------+------------------------\n");
        echo '</pre>';
    ?>

    Giving

    Month         Fiscal month
                Saturday — Friday    
    --------+------------------------
    2017-11 | 2017-10-28 — 2017-11-24
    2017-12 | 2017-11-25 — 2017-12-29
    2018-01 | 2017-12-30 — 2018-01-26
    2018-02 | 2018-01-27 — 2018-02-23
    2018-03 | 2018-02-24 — 2018-03-30
    2018-04 | 2018-03-31 — 2018-04-27
    2018-05 | 2018-04-28 — 2018-05-25
    2018-06 | 2018-05-26 — 2018-06-29
    2018-07 | 2018-06-30 — 2018-07-27
    2018-08 | 2018-07-28 — 2018-08-31
    2018-09 | 2018-09-01 — 2018-09-28
    2018-10 | 2018-09-29 — 2018-10-26
    2018-11 | 2018-10-27 — 2018-11-30
    2018-12 | 2018-12-01 — 2018-12-28
    2019-01 | 2018-12-29 — 2019-01-25
    2019-02 | 2019-01-26 — 2019-02-22
    2019-03 | 2019-02-23 — 2019-03-29
    2019-04 | 2019-03-30 — 2019-04-26
    2019-05 | 2019-04-27 — 2019-05-31
    2019-06 | 2019-06-01 — 2019-06-28
    2019-07 | 2019-06-29 — 2019-07-26
    2019-08 | 2019-07-27 — 2019-08-30
    2019-09 | 2019-08-31 — 2019-09-27
    2019-10 | 2019-09-28 — 2019-10-25
    --------+------------------------

     

  9. You can generate a date preiod object to loop through a range of months

    <?php
    // CREATE A RANGE OF MONTHS
    $dt1 = new DateTime('2019-01-01');
    $dt2 = new DateTime('2020-01-01');
    $months = [];
    $dp = new DatePeriod($dt1, new DateInterval('P1M'), $dt2);
    
    // STARTING FRIDAY
    $prev_fri = new DateTime('last friday of december 2018');
    
    // LOOP THROUGH THE MONTHS
    foreach ($dp as $d) {
        $key = $d->format('Y-m');
        $months[$key]['start'] = $prev_fri->modify('+1 days')->format('Y-m-d');    // add 1 day to previous friday for start date
        $fri = $d->modify('last friday of this month');                            // get last friday of the month for end date
        $months[$key]['end'] = $fri->format('Y-m-d');
        $prev_fri = $fri;                                                          // store month end
    }
    
    echo '<pre>', print_r($months, 1), '</pre>';
    ?>

    Giving

    Array
    (
        [2019-01] => Array
            (
                [start] => 2018-12-29
                [end] => 2019-01-25
            )
    
        [2019-02] => Array
            (
                [start] => 2019-01-26
                [end] => 2019-02-22
            )
    
        [2019-03] => Array
            (
                [start] => 2019-02-23
                [end] => 2019-03-29
            )
    
        [2019-04] => Array
            (
                [start] => 2019-03-30
                [end] => 2019-04-26
            )
    
        [2019-05] => Array
            (
                [start] => 2019-04-27
                [end] => 2019-05-31
            )
    
        [2019-06] => Array
            (
                [start] => 2019-06-01
                [end] => 2019-06-28
            )
    
        [2019-07] => Array
            (
                [start] => 2019-06-29
                [end] => 2019-07-26
            )
    
        [2019-08] => Array
            (
                [start] => 2019-07-27
                [end] => 2019-08-30
            )
    
        [2019-09] => Array
            (
                [start] => 2019-08-31
                [end] => 2019-09-27
            )
    
        [2019-10] => Array
            (
                [start] => 2019-09-28
                [end] => 2019-10-25
            )
    
        [2019-11] => Array
            (
                [start] => 2019-10-26
                [end] => 2019-11-29
            )
    
        [2019-12] => Array
            (
                [start] => 2019-11-30
                [end] => 2019-12-27
            )
    
    )

     

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