Jump to content
php.lv forumi

knauzers

Reģistrētie lietotāji
  • Content Count

    17
  • Joined

  • Last visited

About knauzers

  • Rank
    Māceklis

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Jautājums, vai DUPLICATE KEY... sadaļu varu kaut kā kombinēt ar implode? Vai arī implode izslēdzam no koda?
  2. Kods ir jēdzīgs tādā ziņā, ka tas ir kalnedārs ar fiksētām dropdown vērtībām, kuras jānosūta uz SQL datubāzi, no kuras savukārt cita aplikācija šos datus lasīs. Es eju soli pa solim, līdz ar to kādā brīdī kāda darbība var šķist (un lielākoties pamatoti) lieka... ;)
  3. Primkārt, paldies par atklātību. Man, šo visu būvējot, uzraiz bija skaidrs, ka diži optimāls šis kods nebūs. :D Par tēmu - mazliet nesaprati. Tabulā viss saglabājas. Mana ideja bija, lai izvēlētie dropdown lauki pēc POST darbības saglabā savas vērtības web lapā. Šobrīd man pēc Submit pogas nospiešanas visi dropdown lauki atkrīt uz defaultajām " ... " vērtībām. Pieņemu, ka šeit kā viens no soļiem ir ieviest Tevis minēto UPDATE funkciju SQL tabulai.
  4. Sorry, kods: <?php // Set your timezone date_default_timezone_set('Europe/Riga'); // Get prev & next month if (isset($_GET['ym'])) { $ym = $_GET['ym']; } else { // This month $ym = date('Y-m'); } // Check format $timestamp = strtotime($ym . '-01'); if ($timestamp === false) { $ym = date('Y-m'); $timestamp = strtotime($ym . '-01'); } // Today $today = date('Y-m-j', time()); // For H3 title $html_title = date('Y / m', $timestamp); // Create prev & next month link mktime(hour,minute,second,month,day,year) $prev = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)-1, 1, date('Y', $timestamp))); $next = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)+1, 1, date('Y', $timestamp))); // You can also use strtotime! // $prev = date('Y-m', strtotime('-1 month', $timestamp)); // $next = date('Y-m', strtotime('+1 month', $timestamp)); // Number of days in the month $day_count = date('t', $timestamp); // 0:Sun 1:Mon 2:Tue ... $str = date('w', mktime(0, 0, 0, date('m', $timestamp), 0, date('Y', $timestamp))); //$str = date('w', $timestamp); // Create Calendar!! $weeks = array(); $week = ''; // Add empty cell $week .= str_repeat('<td></td>', $str); for ( $day = 1; $day <= $day_count; $day++, $str++) { $date = $ym . '-' . $day; if ($today == $date) { $week .= '<td class="today">' . $day; } else { $week .= '<td>' . $day; } $week .= '<br>'; $week .= '<select name="day_' . $day . '" style="background-color:#01A9DB;">'; $week .= '<option value="0">...</option>'; $week .= '<option value="A">A</option>'; $week .= '<option value="B">B</option>'; $week .= '<option value="C">C</option>'; $week .= '<option value="D">D</option>'; $week .= '<option value="E">E</option>'; $week .= '<option value="F">F</option>'; $week .= '</select>'; $week .= '</td>'; // End of the week OR End of the month if ($str % 7 == 6 || $day == $day_count) { if ($day == $day_count) { // Add empty cell $week .= str_repeat('<td></td>', 6 - ($str % 7)); } $weeks[] = '<tr>' . $week . '</tr>'; // Prepare for new week $week = ''; } } // DELETE LOOP if (isset($_POST['day_1'])) { $sql_parts = []; for ( $day = 1; $day <= $day_count; $day++) { $date = $ym . '-' . $day; $test = null; $key = 'day_' . $day; if (isset($_POST[$key])) { $test = $_POST[$key]; } $sql_parts[] = "('$date', '$test')"; } if ($sql_parts) { $link = mysqli_connect("localhost", "root", "xxx", "yyy"); if ($link === false) { die("Maintenance code #1234."); } $implodeArray = implode(',', $sql_parts); $sql = "TRUNCATE TABLE dezuranti"; if (mysqli_query($link, $sql)){ echo ""; } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } mysqli_close($link); } } // INSERT LOOP if (isset($_POST['day_1'])) { $sql_parts = []; for ( $day = 1; $day <= $day_count; $day++) { $date = $ym . '-' . $day; $test = null; $key = 'day_' . $day; if (isset($_POST[$key])) { $test = $_POST[$key]; } $sql_parts[] = "('$date', '$test')"; } if ($sql_parts) { $link = mysqli_connect("localhost", "root", "xxx", "yyy"); if ($link === false) { die("Maintenance code #1234."); } $implodeArray = implode(',', $sql_parts); $sql = "INSERT INTO dezuranti VALUES " .$implodeArray; if (mysqli_query($link, $sql)){ echo "<p> <font color=#01DFA5> <b><i>OK</i></b></font> </p>"; } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } mysqli_close($link); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>TITLE</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet"> <style> .container { font-family: 'Noto Sans', sans-serif; margin-top: 10px; width: auto; } .button { height: 70px; width: 30%; color: black; font-size: 13px; background-color: #A9F5E1; text-align:center; margin-left:600px; } .button:hover { background-color: #01DFA5; color: black; } h3 { margin-bottom: 100px; } th { height: 10px; text-align: center; font-size: 19px; } td { height: 10px; background-color: #A9F5E1; font-style: italic; font-size: 13px; font-weight: bold; } .today { background: orange; } </style> </head> <body style="background-color:#0B4C5F;"> <div class="container"> <h2 style="color:#01DFA5">Nosaukums <a href="?ym=<?php echo $prev; ?>">&lt;</a> <?php echo $html_title; ?> <a href="?ym=<?php echo $next; ?>">&gt;</a></h2> <form method="post"> <table class="table table-bordered" > <tr bgcolor="#01DFA5"> <th>Pr</th> <th>Ot</th> <th>Tr</th> <th>Ce</th> <th>Pi</th> <th style="color:red">Se</th> <th style="color:red">Sv</th> </tr> <?php foreach ($weeks as $week) { echo $week; } ?> </table> <input class="button" type="submit" value="Submit!"> </form> </div> </body> </html>
  5. Te nu nākošais jautājums - par dropdown vaule saglabāšanu pēc submit. Izmēģināju dažādus variantus, sagrābstītus pa ārzemju forumiem, taču bez panākumiem. Varbūt ir kādi ieteikumi, kādā virzienā iet? @e-remit
  6. Lieliski, viss strādā! Mežonīgs paldies! Turpināšu būvdarbus, varbūt vēl ar kādu jautājumu patraucēšu...
  7. Paldies Tev liels. Vari vēl lūdzu paskaidrot šis rindas funkcionalitāti: " $test = isset($_POST['day_' . $day]) ? (int)$_POST['day_' . $day] : null; " Tobiš, kas tiek panākts ar šo rindu?
  8. Kods: <?php // Set your timezone date_default_timezone_set('Europe/Riga'); // Get prev & next month if (isset($_GET['ym'])) { $ym = $_GET['ym']; } else { // This month $ym = date('Y-m'); } // Check format $timestamp = strtotime($ym . '-01'); if ($timestamp === false) { $ym = date('Y-m'); $timestamp = strtotime($ym . '-01'); } // Today $today = date('Y-m-j', time()); // For H3 title $html_title = date('Y / m', $timestamp); // Create prev & next month link mktime(hour,minute,second,month,day,year) $prev = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)-1, 1, date('Y', $timestamp))); $next = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)+1, 1, date('Y', $timestamp))); // You can also use strtotime! // $prev = date('Y-m', strtotime('-1 month', $timestamp)); // $next = date('Y-m', strtotime('+1 month', $timestamp)); // Number of days in the month $day_count = date('t', $timestamp); // 0:Sun 1:Mon 2:Tue ... $str = date('w', mktime(0, 0, 0, date('m', $timestamp), 0, date('Y', $timestamp))); //$str = date('w', $timestamp); // Create Calendar!! $weeks = array(); $week = ''; // Add empty cell $week .= str_repeat('<td></td>', $str); for ( $day = 1; $day <= $day_count; $day++, $str++) { $date = $ym . '-' . $day; if ($today == $date) { $week .= '<td class="today">' . $day; } else { $week .= '<td>' . $day; } $week .= '<select name="name" style="background-color:#01A9DB;">'; $week .= '<option value="0">...</option>'; $week .= '<option value="A">A</option>'; $week .= '<option value="B">B</option>'; $week .= '<option value="C">C</option>'; $week .= '<option value="D">D</option>'; $week .= '<option value="E">E</option>'; $week .= '<option value="F">F</option>'; $week .= '</select>'; $week .= '</td>'; if (isset($_POST['name'])) { $test=$_POST['name']; $link = mysqli_connect("localhost", "root", "xxx", "yyy"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Attempt insert query execution $sql = "INSERT INTO d ez ura n ti (Col1, Col2 ) VALUES ('$date', '$test)"; if(mysqli_query($link, $sql)){ echo "Records were updated successfully."; } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); } // End of the week OR End of the month if ($str % 7 == 6 || $day == $day_count) { if ($day == $day_count) { // Add empty cell $week .= str_repeat('<td></td>', 6 - ($str % 7)); } $weeks[] = '<tr>' . $week . '</tr>'; // Prepare for new week $week = ''; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>TITLE</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet"> <style> .container { font-family: 'Noto Sans', sans-serif; margin-top: 10px; width: auto; } .button { height: 70px; width: 30%; color: black; font-size: 13px; background-color: #A9F5E1; text-align:center; margin-left:600px; } .button:hover { background-color: #01DFA5; color: black; } h3 { margin-bottom: 100px; } th { height: 10px; text-align: center; font-size: 19px; } td { height: 10px; background-color: #A9F5E1; font-style: italic; font-size: 13px; font-weight: bold; } .today { background: orange; } </style> </head> <body style="background-color:#0B4C5F;"> <div class="container"> <h2 style="color:#01DFA5">NOSAUKUMS <a href="?ym=<?php echo $prev; ?>">&lt;</a> <?php echo $html_title; ?> <a href="?ym=<?php echo $next; ?>">&gt;</a></h2> <form method="post"> <table class="table table-bordered" > <tr bgcolor="#01DFA5"> <th>Pr</th> <th>Ot</th> <th>Tr</th> <th>Ce</th> <th>Pi</th> <th style="color:red">Se</th> <th style="color:red">Sv</th> </tr> <?php foreach ($weeks as $week) { echo $week; } ?> </table> <input class="button" type="submit" value="Submit!"> </form> </div> <br> <br> <table style="width:15%;bgcolor:white"> <tr> <td style="background-color:#FA5882;width:60px;">.</td> <td>Operativas lietas</td> </tr> <tr> <td style="background-color:#F3F781;width:60px;">.</td> <td>Projekti</td> </tr> <tr> <td style="background-color:#01A9DB;width:60px;">.</td> <td>Dienas dezurants</td> </tr> </table> </body> </html>
  9. Atgriežos pie problēmas risināšanas. Ar Tevis ieteikto metodi esmu turpat, kur biju - joprojām iegūstu šo: Varbūt kods kā tāds vairs nav tūnējams un ir, tā teikt, izsmēlis sevi ,līdz ar to jādomā kas fundamentāli savādāks?
  10. Tad jautājums, kā lai šo padara dinamisku? Es, protams, nesagaidu gatavu kodu, bet vismaz virzienu... :)
  11. Tur tā lieta, ka skripts izpildās veiksmīgi, SQL tabulā iegūstu $date vērtības 01-12-2018, 02-12-2018 ..... 31-12.2018, taču $test3 vērtība visām atbilstošajām decembra dienām ir viena un tā pati - pēdējās mēneša dienas dropdown value. Idejiski: Vēlamais rezultāts: 01-12-2018 -> x 02-12-2018 -> y 03-12-2018 -> z Esošais rezultāts: 01-12-2018 -> z 02-12-2018 -> z 03-12-2018 -> z Otra koda daļa, kuru iepriekš neieliku: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>TITLE</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet"> <style> .container { font-family: 'Noto Sans', sans-serif; margin-top: 10px; width: auto; } .button { height: 70px; width: 30%; color: black; font-size: 13px; background-color: #A9F5E1; text-align:center; margin-left:600px; } .button:hover { background-color: #01DFA5; color: black; } h3 { margin-bottom: 100px; } th { height: 10px; text-align: center; font-size: 19px; } td { height: 10px; background-color: #A9F5E1; font-style: italic; font-size: 13px; font-weight: bold; } .today { background: orange; } </style> </head> <body style="background-color:#0B4C5F;"> <div class="container"> <h2 style="color:#01DFA5">NOSAUKUMS <a href="?ym=<?php echo $prev; ?>">&lt;</a> <?php echo $html_title; ?> <a href="?ym=<?php echo $next; ?>">&gt;</a></h2> <form method="post"> <table class="table table-bordered" > <tr bgcolor="#01DFA5"> <th>Pr</th> <th>Ot</th> <th>Tr</th> <th>Ce</th> <th>Pi</th> <th style="color:red">Se</th> <th style="color:red">Sv</th> </tr> <?php foreach ($weeks as $week) { echo $week; } ?> </table> <input class="button" type="submit" value="Submit!"> </form> </div> </body> </html>
  12. Tu domā celt <select> tagu (un visu tā saturu) zem HTML koda, iekš formas? Vai tādā gadījumā es nepazaudēšu dropdown izvēli visās mēneša dienās, ko man šobrīd nodrošina PHP? Sorry, ja mani jautājumi ir muļķīgi, vēl apgūstu vielu... :)
  13. Sorry, kods šāds: <?php date_default_timezone_set('Europe/Riga'); if (isset($_GET['ym'])) { $ym = $_GET['ym']; } else { $ym = date('Y-m'); } $timestamp = strtotime($ym . '-01'); if ($timestamp === false) { $ym = date('Y-m'); $timestamp = strtotime($ym . '-01'); } $today = date('Y-m-j', time()); $html_title = date('Y / m', $timestamp); $prev = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)-1, 1, date('Y', $timestamp))); $next = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)+1, 1, date('Y', $timestamp))); $day_count = date('t', $timestamp); $str = date('w', mktime(0, 0, 0, date('m', $timestamp), 0, date('Y', $timestamp))); $weeks = array(); $week = ''; $week .= str_repeat('<td></td>', $str); for ( $day = 1; $day <= $day_count; $day++, $str++) { $date = $ym . '-' . $day; if ($today == $date) { $week .= '<td class="today">' . $day; } else { $week .= '<td>' . $day; } $week .= '<br>'; $week .= '<select name="name">'; $week .= '<option value="test">test</option>'; $week .= '<option value="test2">test2</option>'; $week .= '</select>'; $test3=$_POST['name']; $link = mysqli_connect("localhost", "root", "xxx", "yyy"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Attempt insert query execution $sql = "INSERT INTO dezuranti (Col1, Col2) VALUES ('$date', '$test3)"; if(mysqli_query($link, $sql)){ echo "Records were updated successfully."; } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); if ($str % 7 == 6 || $day == $day_count) { if ($day == $day_count) { // Add empty cell $week .= str_repeat('<td></td>', 6 - ($str % 7)); } $weeks[] = '<tr>' . $week . '</tr>'; // Prepare for new week $week = ''; } } Tālāk ir HTML būvēta tabula iekš formas un Submit poga, lai to visu aizsūtītu uz SQL tabulu.
×
×
  • Create New...