Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/16/2022 in all areas

  1. Yes, use services you configure. Make sure that you have passed in any related class objects you need to class constructors, including inside controllers.
    1 point
  2. Facades are aliases defined in the config/app.php. Look in that file for the "aliases" key and you'll find the mappings. With that said, so long as they remain a part of Laravel, if you want to avoid using them (which is a good idea, especially if you want to have sensible unit tests) then just don't use them. There isn't an option to remove them or disable them entirely, and no plan that I know of to do so. They are a convenience option, but you are not forced to, nor required to ever use a facade.
    1 point
  3. $test = [ '0000' => [2 =>'tes000'], '1111' => [0=>'tes1', 1=>'tes11', 2 =>'tes111'], '2222' => [0=>'tes2', 2 =>'tes333'] ] ; $test = array_map( function($v) { return array_replace(array_fill_keys(range(0,2), 'NIL'), $v); } , $test); echo '<pre>' . print_r($test, 1) . '</pre>'; giving Array ( [0000] => Array ( [0] => NIL [1] => NIL [2] => tes000 ) [1111] => Array ( [0] => tes1 [1] => tes11 [2] => tes111 ) [2222] => Array ( [0] => tes2 [1] => NIL [2] => tes333 ) )
    1 point
  4. Given you current structure that could only be a good thing to do. Your date storage format is useless. Can't be processed or sorted. Always store in yyyy-mm-dd format (type DATE) You shouldn't store age, it needs continual updating and can be easily derived from a correctly formatted date (SELECT timestampdiff(YEAR, curdate(), birthday) as age ) Description like "SuperCar" should appear once in a database and not be used as FKs. Only ids should occur in more that one table. If one of your people buys a "Hot Air Balloon" it won't appear on the form to add the option as no-one currenly has one. (In my design I merely add another record to "Vehicle_type" table - job done.) I have rewritten my query and code to use your database structure. I had to use a subquery to get the available vehicle types instead of my table) // connect to DB here if ($_SERVER['REQUEST_METHOD']=='POST') { // echo '<pre>' . print_r($_POST, 1) . '</pre>'; try { $db->beginTransaction(); $stmt1 = $db->prepare("DELETE FROM vehicle WHERE formid = ? "); $stmt1->execute( [ $_POST['formid'] ] ); if (isset($_POST['trans'])) { $stmt2 = $db->prepare("INSERT INTO vehicle (formid, vehselection) VALUES (?, ?) "); foreach ($_POST['trans'] as $veh) { $stmt2->execute( [ $_POST['formid'], $veh ] ); } } $db->commit(); } catch(PDOException $e) { $db->rollBack(); throw $e; } header("Refresh: 0"); exit; } $res = $db->query("SELECT f.formid , f.name , f.lastname , fv.vehselection , CASE WHEN v.vehselection IS NULL THEN 0 ELSE 1 END AS checked FROM form f CROSS JOIN ( SELECT DISTINCT vehselection FROM vehicle ) fv LEFT JOIN vehicle v ON f.formid = v.formid AND v.vehselection = fv.vehselection ORDER BY lastname, vehselection "); $data = []; // store results in a conveniently structured array foreach ($res as $r) { if (!isset($data[$r['formid']])) { $data[$r['formid']] = [ 'name' => "{$r['name']} {$r['lastname']}", 'trans' => [] ]; } $data[$r['formid']]['trans'][$r['vehselection']] = $r['checked']; } //echo '<pre>' . print_r($data, 1) . '</pre>'; # view array structure //exit; ?> <!DOCTYPE html> <html lang='en'> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="generator" content="PhpED 19.5 (Build 19523, 64bit)"> <title>Example</title> <meta name="author" content="Barand"> <meta name="creation-date" content="04/09/2022"> <style type='text/css'> table { border-collapse: collapse; margin: 20px auto; width: 60%; } td, th { padding: 8px; } </style> </head> <body> <table border='1'> <tr> <th>Name</th> <th>Transport types</th> <th>&nbsp;</th> </tr> <?php // output the array foreach ($data as $fid => $udata) { echo "<tr> <form method='post'> <td>{$udata['name']}</td> <td>"; foreach ($udata['trans'] as $ttype => $check) { $chk = $check ? 'checked' : ''; echo "<label><input type='checkbox' name='trans[]' value='$ttype' $chk>$ttype</label><br>"; } echo "</td> <td> <input type='hidden' name='formid' value='$fid'> <input type='submit' value='Update'> </td> </form> </tr> "; } ?> </table> </body> </html>
    0 points
This leaderboard is set to New York/GMT-04:00
×
×
  • 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.