Jump to content
php.lv forumi

knauzers

Reģistrētie lietotāji
  • Content Count

    12
  • Joined

  • Last visited

About knauzers

  • Rank
    Māceklis
  1. knauzers

    PHP kalnedārs ar dropdown

    Lieliski, viss strādā! Mežonīgs paldies! Turpināšu būvdarbus, varbūt vēl ar kādu jautājumu patraucēšu...
  2. knauzers

    PHP kalnedārs ar dropdown

    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?
  3. knauzers

    PHP kalnedārs ar dropdown

    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>
  4. knauzers

    PHP kalnedārs ar dropdown

    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?
  5. knauzers

    PHP kalnedārs ar dropdown

  6. knauzers

    PHP kalnedārs ar dropdown

    Tad jautājums, kā lai šo padara dinamisku? Es, protams, nesagaidu gatavu kodu, bet vismaz virzienu... :)
  7. knauzers

    PHP kalnedārs ar dropdown

    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>
  8. knauzers

    PHP kalnedārs ar dropdown

    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... :)
  9. knauzers

    PHP kalnedārs ar dropdown

    Anybody? :/
  10. knauzers

    PHP kalnedārs ar dropdown

    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.
  11. knauzers

    PHP kalnedārs ar dropdown

    Sveiki, esmu iesācējs programmēšanā. Ir dinamiski (PHP) veidots kalendārs, ar dropdown izvēlni katrā no mēneša dienām. Nepieciešams datumu un dropdown izvēlēto opciju aizsūtīt uz SQL tabulu. Ir problēmas tieši ar dropdown value nosūtīšanu. Principā nosūtīta visām mēneša dienām tiek pēdējās dienas dropdown izvēle. Saprotu, ka kaut kur pietrūkst kāds LOOPS. Varbūt ir kādi padomi / norādījumi, kā šis būtu korekti jārealizē? Paldies jau iepriekš!
×