Jump to content

Barand

Moderators
  • Posts

    24,607
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. e.g. A custom UOM of "furlongs per fortnight" makes the top speed of your car sound very impressive.
  2. Well, you've output a table of 0s and 1s, but what are you going to count? Store the random 0/1s in a two-dimensional array then count the array contents. Output the array into the table.
  3. Really!? Hard to believe that, with your markup, you are actually using css files.
  4. Looks like the prepare() failed. Put this line before your mysqli connection so that errors are trapped mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); (if you don't have display_errors ON check your error log.)
  5. 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 --------+------------------------
  6. Why would it need a default name to output the image in the browser? Or are you wanting the user to download the image?
  7. Like this example in this topic 1) Read your replies 2) Don't repeatedly post the same question.
  8. 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 ) )
  9. update the image's src attribute when date changes
  10. 1) you could get the date in PHP, or 2) build the image url in javascript HTML <img src="" id="myimg" > JS <script type="text/javascript"> var my_js_date var imgurl = "myimage.php?date=" + my_js_date $().ready( function() { $("#myimg").attr("src",imgurl); }) </script>
  11. Or you could pass the user_id (or other data) in the query string as I did with the "txt" value in the example above.
  12. It helps when we know what the problem is - what is happening/not happening? Put code in code tags (Use <> button in the toolbar)
  13. Main page contains image tag <img src='myimage.php?txt=Hello+world'> myimage.php $img = imagecreatefromjpeg('balloon.jpg'); $white = imagecolorallocate($img, 255, 255, 255); $txt = $_GET['txt'] ?? ''; $font = "C:/Windows/Fonts/arial.ttf"; imagettftext($img, 24, 0, 5, 24, $white, $font, $txt); // OUTPUT IMAGE header('Content-type: image/jpeg'); imagejpeg($img); imagedestroy($img);
  14. There's an old adage that says when faced with "the horns of dilemma" ... … look for a third alternative. I was trying to provide one for you.
  15. Motors drive cars; cars do not drive motors, ergo ... You could sidestep the question if you can't make your mind up +------------+ +------------+ +------------+ | car |---------<| car_motor |>-----------| motor | +------------+ +------------+ +------------+ Nothing says there have to be "many" in a many-to-many type structure
  16. It's in mac_gyver's post that you just replied to ... Do you not bother to read replies? Here's a sample script to illustrate the point <?php session_start(); $_SESSION['cart'] = $_SESSION['cart'] ?? []; if ($_SERVER['REQUEST_METHOD']=='POST') { $post = array_map('trim', $_POST); if (!empty($post['productid']) && !empty($post['qty'])) { if (!isset($_SESSION['cart'][$_POST['productid']])) { $_SESSION['cart'][$_POST['productid']] = 0; } $_SESSION['cart'][$_POST['productid']] += $_POST['qty']; } } ?> <!DOCTYPE html> <html> <head> <title>Example</title> <style type="text/css"> body { font-family: verdana, arial, sans-serif; font-size: 11pt; } fieldset { width: 400px; padding: 8px; } legend {background-color: #000; color: #FFF; padding: 4px; } label { display: inline-block; width: 100px; } </style> </head> <body> <?= '<pre>Cart = ' . print_r($_SESSION['cart'], 1) . '</pre>' ?> <form method="post"> <fieldset style='padding: 30px; width:400px;'> <legend>Add product to cart</legend> <label>Product</label> <select name='productid' required> <option value=''>- Choose product -</option> <option value='PROD1'>Widget</option> <option value='PROD2'>Gizmo</option> <option value='PROD3'>Wotsit</option> <option value='PROD4'>Thingy</option> </select> <br><br> <label>Quantity</label> <input type="number" name="qty" value="1" size="5" required> <br><br> <label></label> <input type="submit" name="btnSub" value="Submit"> </fieldset> </form> </body> </html> Screenshot:
  17. I have mine set up like this <?php // DEFINE CONNECTION CREDENTIALS const HOST = 'localhost'; const USERNAME = 'user'; const PASSWORD = 'pwd'; const DBNAME = 'dbname'; // MYSQLI CONNECTION function myConnect($dbname=DBNAME) { mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $db = mysqli_connect(HOST,USERNAME,PASSWORD,$dbname); $db->set_charset('utf8'); return $db; } //PDO CONNECTION function pdoConnect($dbname=DBNAME) { $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $db; } Then if I want a mysqli connection require 'database.php'; $db = myConnect(); and for a PDO connection (strongly recommended) require 'database.php'; $db = pdoConnect();
  18. Tested that with IE, Firefox, Edge and Chrome and that is the case. I'm pretty sure that older IE versions didn't though.
  19. Having read the error message, were you not tempted to read the reference manual for mysqli_query() to see what the correct parameters should be?
  20. Perhaps it's just as well. That would take the relationship to 1-to-many or, potentially, a many-to-many.
  21. But no service record of those replacements - what , where, when ?
  22. No provision in your system then for a motor needing to be replaced?
  23. Simple mathematics is usually reliable.
  24. Correct, but I was trying to illustrate where his method was going wrong by showing how his approach should be used.
×
×
  • 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.