Стани премиум член, добиј куп бенефити и поддржи ја работата на IT.mk!
  • Важно
    Имате проблем со најава или регистрација на it.mk?
    Побарајте го решението на вашиот проблем ТУКА!

автоматски преместување на текст во групи

Miki98

Gaining Experience
13 јануари 2021
466
280
Macedonia Pehchevo [2326]
www.balkan77.com
Здраво ит другари
дали може некој да ми помогне за оваа
сакам да направам табела каде што има текст,но текстот секоја сабота или недела автоматски да се ротира на |група3| група2| и |група1|
текстот пр.
учење
пракса
вежби
|група3| група2| и |група1|
учење | пракса| |вежби|
кога помине сабота или Недела авотматски да се ротира тесктот
|група3| група2| и |група1|
вежби | учење| и | пракса|
мислам дека ме сфативте.
незнам како да го направам све грешки покажува.
ете index.php
Код:
<?php
// Include the database connection
include('connection.php');

// Define the group order
$group_order = array('group3', 'group2', 'group1');

// Update the user text and move them to a different group on Sunday
function update_users_text() {
    // Get the current date
    $current_date = date('Y-m-d');
 
    // Check if it's Sunday
    if (date('N', strtotime($current_date)) === '7') {
        // Get the current order of the groups
        global $group_order;
        $group_count = count($group_order);
     
        // Update the user text and move them to a different group
        $sql = "UPDATE users SET user_text = CONCAT(user_text, ' - Updated on Sunday')";

        // Loop through each group in reverse order
        for ($i = $group_count - 1; $i >= 0; $i--) {
            // Move the users to the previous group
            $prev_group = ($i - 1 >= 0) ? $group_order[$i - 1] : $group_order[$group_count - 1];
            $group = $group_order[$i];
            $sql .= " WHERE group_name = '$group' SET group_name = '$prev_group'";
        }

        // Execute the SQL query
        global $conn;
        mysqli_query($conn, $sql);
    }
}

// Call the function to update the user text and group
update_users_text();

// Fetch the users from the database
$sql = "SELECT * FROM users ORDER BY group_name DESC, user_id ASC";
$result = mysqli_query($conn, $sql);

// Create the table
echo '<table border="1">';
echo '<tr><th>Username</th><th>Group</th><th>User Text</th></tr>';
while ($row = mysqli_fetch_assoc($result)) {
    echo '<tr><td>'.$row['username'].'</td><td>'.$row['group_name'].'</td><td>'.$row['user_text'].'</td></tr>';
}
echo '</table>';

// Close the database connection
mysqli_close($conn);
?>
connection.php
Код:
<?php
// Replace the values in the following line with your own database name, username, and password
$conn = mysqli_connect('localhost', 'username', 'password', 'database_name');

// Check the connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
?>

во phpmyadmin или друга датабаза на микрософт:
Код:
CREATE TABLE users (
  id INT(11) NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  group_id INT(11) NOT NULL,
  last_updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
);
благодарам однапред
 
Последна промена:

Users

Intern
27 декември 2019
41
37
Кодот прави UPDATE на колона user_text и во WHERE споредува вредност на колона group_name, но и двете не се креирани со CREATE TABLE. И во
Код:
for ($i = $group_count - 1; $i >= 0; $i--) {
повеќе пати ќе додаде WHERE на SQL query а треба да има само едно.
 

Miki98

Gaining Experience
13 јануари 2021
466
280
Macedonia Pehchevo [2326]
www.balkan77.com
Кодот прави UPDATE на колона user_text и во WHERE споредува вредност на колона group_name, но и двете не се креирани со CREATE TABLE. И во
Код:
for ($i = $group_count - 1; $i >= 0; $i--) {
повеќе пати ќе додаде WHERE на SQL query а треба да има само едно.

Кодот прави UPDATE на колона user_text и во WHERE споредува вредност на колона group_name, но и двете не се креирани со CREATE TABLE. И во
Код:
for ($i = $group_count - 1; $i >= 0; $i--) {
повеќе пати ќе додаде WHERE на SQL query а треба да има само едно.
Неможам да го направам, лаптопот ме зеза нешто,ми треба да инсталирам windows server, бидејќи е полесно
Оваа сакам да го направам, бидејќи ми треба,да речеме кога внесуваш некој текст да го памти во која група е,и која дата е,кога се променила недела и датата да се смени.
Код:
<?php
// Include the database connection file
include 'connection.php';

// Get the list of groups from the database
$sql = "SELECT DISTINCT `group` FROM `users` ORDER BY `group` ASC";
$result = mysqli_query($conn, $sql);

// Create a dropdown list of groups
echo '<form method="POST">';
echo 'Select a group: <select name="group">';
while ($row = mysqli_fetch_assoc($result)) {
    echo '<option value="'.$row['group'].'">'.$row['group'].'</option>';
}
echo '</select>';

// Get the list of positions within the selected group from the database
$group = $_POST['group'];
$sql = "SELECT DISTINCT `position` FROM `users` WHERE `group`='$group' ORDER BY `position` ASC";
$result = mysqli_query($conn, $sql);

// Create a dropdown list of positions within the selected group
echo 'Select a position: <select name="position">';
while ($row = mysqli_fetch_assoc($result)) {
    echo '<option value="'.$row['position'].'">'.$row['position'].'</option>';
}
echo '</select>';

// Get the list of users in the selected position within the selected group from the database
$position = $_POST['position'];
$sql = "SELECT `name` FROM `users` WHERE `group`='$group' AND `position`='$position' ORDER BY `name` ASC";
$result = mysqli_query($conn, $sql);

// Display a table of users in the selected position within the selected group
echo '<table>';
echo '<tr><th>Name</th></tr>';
while ($row = mysqli_fetch_assoc($result)) {
    echo '<tr><td>'.$row['name'].'</td></tr>';
}
echo '</table>';
echo '</form>';
?>
Оваа е за дата
Код:
// query the database to get the list of users and their groups
$sql = "SELECT u.username, u.group, g.last_updated_date FROM users u JOIN groups g ON u.group = g.name ORDER BY u.group DESC";
$result = $conn->query($sql);

// check if there are any results
if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
    // display the username, group, and last updated date in a table row
    echo "<tr>";
    echo "<td>" . $row["username"] . "</td>";
    echo "<td>" . $row["group"] . "</td>";
    
    // check if the text was updated today
    if ($row["last_updated_date"] == $current_date) {
      // display the date in black
      echo "<td>" . $row["last_updated_date"] . "</td>";
    } else {
      // display the date in red
      echo '<td style="color: red;">' . $row["last_updated_date"] . '</td>';
    }
    
    echo "</tr>";
  }
} else {
  echo "0 results";
}
Мислењето е автоматски споено:

Неможам да го направам, лаптопот ме зеза нешто,ми треба да инсталирам windows server, бидејќи е полесно
Оваа сакам да го направам, бидејќи ми треба,да речеме кога внесуваш некој текст да го памти во која група е,и која дата е,кога се променила недела и датата да се смени.
Код:
<?php
// Include the database connection file
include 'connection.php';

// Get the list of groups from the database
$sql = "SELECT DISTINCT `group` FROM `users` ORDER BY `group` ASC";
$result = mysqli_query($conn, $sql);

// Create a dropdown list of groups
echo '<form method="POST">';
echo 'Select a group: <select name="group">';
while ($row = mysqli_fetch_assoc($result)) {
    echo '<option value="'.$row['group'].'">'.$row['group'].'</option>';
}
echo '</select>';

// Get the list of positions within the selected group from the database
$group = $_POST['group'];
$sql = "SELECT DISTINCT `position` FROM `users` WHERE `group`='$group' ORDER BY `position` ASC";
$result = mysqli_query($conn, $sql);

// Create a dropdown list of positions within the selected group
echo 'Select a position: <select name="position">';
while ($row = mysqli_fetch_assoc($result)) {
    echo '<option value="'.$row['position'].'">'.$row['position'].'</option>';
}
echo '</select>';

// Get the list of users in the selected position within the selected group from the database
$position = $_POST['position'];
$sql = "SELECT `name` FROM `users` WHERE `group`='$group' AND `position`='$position' ORDER BY `name` ASC";
$result = mysqli_query($conn, $sql);

// Display a table of users in the selected position within the selected group
echo '<table>';
echo '<tr><th>Name</th></tr>';
while ($row = mysqli_fetch_assoc($result)) {
    echo '<tr><td>'.$row['name'].'</td></tr>';
}
echo '</table>';
echo '</form>';
?>
Оваа е за дата
Код:
// query the database to get the list of users and their groups
$sql = "SELECT u.username, u.group, g.last_updated_date FROM users u JOIN groups g ON u.group = g.name ORDER BY u.group DESC";
$result = $conn->query($sql);

// check if there are any results
if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
    // display the username, group, and last updated date in a table row
    echo "<tr>";
    echo "<td>" . $row["username"] . "</td>";
    echo "<td>" . $row["group"] . "</td>";
   
    // check if the text was updated today
    if ($row["last_updated_date"] == $current_date) {
      // display the date in black
      echo "<td>" . $row["last_updated_date"] . "</td>";
    } else {
      // display the date in red
      echo '<td style="color: red;">' . $row["last_updated_date"] . '</td>';
    }
   
    echo "</tr>";
  }
} else {
  echo "0 results";
}
Оваа само да го направам дизајнот преубаво можам да го средам.
 

Miki98

Gaining Experience
13 јануари 2021
466
280
Macedonia Pehchevo [2326]
www.balkan77.com
microsoft_edge_screenshot_Apr 18, 2023 2_46_25 AM GMT+02_00.png.png
Код:
<!DOCTYPE html>
<html>
<head>
    <title>Users Group</title>
    <style>
        table, th, td {
              border: 1px solid black;
              border-collapse: collapse;
              padding: 5px;
        }
    </style>
</head>
<body>
    <h1>Users Group</h1>
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Position</th>
                <th>Group 1</th>
                <th>Group 2</th>
                <th>Group 3</th>
                <th>Last Updated</th>
            </tr>
        </thead>
        <tbody>
            <?php
                // Connect to the database
                $servername = "localhost";
                $username = "root";
                $password = "root";
                $dbname = "users_group";
                $conn = new mysqli($servername, $username, $password, $dbname);

                // Check connection
                if ($conn->connect_error) {
                  die("Connection failed: " . $conn->connect_error);
                }

                // Select data from the table
                $sql = "SELECT * FROM users_group";
                $result = $conn->query($sql);

                // Loop through the data and display in the table
                if ($result->num_rows > 0) {
                  while($row = $result->fetch_assoc()) {
                    echo "<tr>";
                    echo "<td>" . $row["id"] . "</td>";
                    echo "<td>" . $row["name"] . "</td>";
                    echo "<td>" . $row["position"] . "</td>";
                    echo "<td>" . $row["group1"] . "</td>";
                    echo "<td>" . $row["group2"] . "</td>";
                    echo "<td>" . $row["group3"] . "</td>";
                    echo "<td>" . $row["last_updated"] . "</td>";
                    echo "</tr>";
                  }
                } else {
                  echo "0 results";
                }

                // Close the database connection
                $conn->close();
            ?>
        </tbody>
    </table>
</body>
</html>
ит другари бидејќи не сум на пц, преку телефон почнав ми дава некои грешки во врска со датабазата дека не е врзана преку апликација
AWebServer и anwriter.
 

Нови мислења

Последни Теми

Статистика

Теми
45.598
Мислења
945.549
Членови
34.082
Огласи
1.974
Најнов член
classicmetal
На врв Дно