Jump to content

All Activity

This stream auto-updates

  1. Today
  2. Is this closer? <input id='mytext' type='text'> <button id='btn'>Create output</button> <br><br> <textarea id='target' cols='80' rows='5'></textarea> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> <script type='text/javascript'> $("#btn").click(function() { let txt = $("#mytext").val() let para = `<p style="background: black; padding: 15px; color:white;">${txt}</p>` $("#target").text(para) }) </script>
  3. Yesterday
  4. This is what I am trying to achieve. Get my original P code listed with the input description. <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>P Code Generator</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> </head> <body> <h1>P Code Generator</h1> <input type="text" id="myInputText" placeholder="Enter Description"> <button onclick="replaceDescription()">Generate Code</button> <script src="myscript.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script> </body> </html> function replaceDescription() { // Get the user input for the Description const myInput = document.getElementById("myInputText").value; // The original text with $description placeholder const originalText = '<p style="background: black; padding: 15px; color:white;"> $description </p>'; // Replace description with the input const replacedText = originalText.replace(/\$description/g, myInput); // Access the element where you want to display the plain text const displayElement = document.getElementById("textDisplay"); // Set the element's textContent to the replaced text (display as plain text) displayElement.textContent = replacedText; }
  5. Hi, regret to confuse, I will show my raw code in a couple of minutes.
  6. Hi, thanks. I was hoping an HTML text input and the output as plain text. So that I can copy the <p> code from browser and paste it. ie, the output is plain text, not styled <p> tag. Something like <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>P Code Generator</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> </head> <body> <h1>P Code Generator</h1> <input type="text" id="myInput" placeholder="Enter Description"> <button onclick="replaceDescription()">Generate Code</button> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script> </body> </html>
  7. Are you looking for something like this? <!DOCTYPE html> <html lang='en'> <head> <meta charset='utf-8'> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> <title>Example</title> <style type='text/css'> p.desc { background-color: black; color: white; padding: 15px; width: 400px; } </style> </head> <body> <div id='target'> <!-- descriptions go here--> </div> <script type='text/javascript'> const texts = [ "Description One", "Decription Two", "Description Three" ] $.each(texts, function(key,txt) { let para = $("<p>", {class:"desc", html:txt}) $("#target").append(para) }) </script> </body> </html>
  8. Hi,I have this code. I need help using a text input to replace the $description in this code <p style="background: black; padding: 15px; color:white;"> $description </p> Because I need to add description many times and can save time if I have a text input that takes in description and displays the above code with text input as plain text. I can then copy paste, use it. Any help will be great.
  9. I don't know what your development platform is, but there are many issues with email deliverability that will be hard to diagnose. For this reason, I highly recommend using a local mail catcher/debugger with one of the best known being Mailhog. Unfortunately mailhog seems to be an abandoned project, so a newer one that is currently maintained is mailpit. Assuming that you have docker installed, you can start mailpit easily using docker run: docker run -d \ --restart unless-stopped \ --name=mailpit \ -p 8025:8025 \ -p 1025:1025 \ axllent/mailpit This will start what looks to client code like an SMTP server available at localhost:1025, and there will be an admin web interface that shows you the emails that are received on port localhost:8025. You would need to change your phpmailer setup slightly for testing, so that you send mail to localhost and port 1025. I don't know if TLS support works or not so you may need to disable the tls settings. I also think it would help you if you studied the concept of dependency injection. For example, whenever you have a method or function that is doing something like this: // Function to send email notification using PHPMailer function sendEmailNotification($recipientEmail, $applicationId, $surname) { // Instantiate PHPMailer $mail = new PHPMailer(true); That should be a sign to you that you probably want to use dependency injection instead. Best practices at this point are to move credentials out of your code base and into .env files or something similar. Having credentials in your code is another vector for security exploitation. If someone gets access to your source code, they have everything they need to connect to your server or in a case like this, send emails to an account. They also make having different environments (dev/test/stage/production) each with different configurations that isolate them from each other. Hopefully you are not developing and testing in production! Most of what you are doing in sendEmailNotification() is setting up PHPMailer. You should move all of that code out into a configuration routine that reads configuration variables from a .env or perhaps a simple php configuration file. Instead of what you are currently doing, you should create and configure your phpmailer object outside the sendEmailNotification function, and pass it as a dependency. // Function to send email notification using PHPMailer function sendEmailNotification(PHPMailer $mail, $recipientEmail, $applicationId, $surname) { You could add a simple function that configures and returns a PHPMailer object, and reads in configuration variables in some other way. There are plenty of libraries out there, to read .ini files, or dotenv etc.
  10. There are a couple of PHP specific commercial addons. The default one isn't very good unfortunately, and you should disable it. I have had good results (as have many other people) using PHP Inteliphense. Inteliphense can be used in basic mode, or you can pay $20 use to get upgraded features. I would start with the free version and see if it is working for you, and then if you like it, consider paying for the extra features. It is very important that you follow the instructions on the page, which has you disable the default php intelisense. Otherwise it will conflict with other php addons. As for xdebug, there isn't one magic way for it to work, because it really depends on how and where you are running php. In the php4lamp docker project I have this config file: Docker4lamp xdebug instructions It is designed to work with this xdebug.ini file (for use with the docker containers). xdebug.ini Of particular interest, and a setting you should look at in the xdebug.ini file is the xdebug.client_host= setting
  11. Thanks so much. With your information I am hoping godaddy will be able to fix this. Charlie
  12. the session.save_path setting in the php.ini is pointing to a now non-existent/non-accessible folder. you need to see of there is already an appropriate folder within your account's directory tree /home/rgxb6tc5wk5q/... for session data files and set the session.save_path setting to point to it, and if a folder doesn't exist, create it and set the session.save_path setting to point to it. when your account was created/moved they should have had templates setup to do this automatically.
  13. I am not sure if this is a cpanel problem or coding problem. I found another post from 4 years ago with almost an identical error code and it had something to do with an ini file in the cpanel i think. I am not very good with the cpanel, so im at a loss. I talked with several people from godaddy yesterday. They said they can't help even though whatever they did caused the problem. This is for a golf leage that I wrote most of the code for several years ago. They could take me back to php 5.6. This was written around 5.2 I believe. I am not very good with php! This is the error I am getting: start error [28-Mar-2024 12:52:36 UTC] PHP Warning: session_start(): open(/var/cpanel/php/sessions/ea-php56/sess_6308705c679006fc92d1c71ffed09d18, O_RDWR) failed: No such file or directory (2) in /home/rgxb6tc5wk5q/public_html/golf/login/login.php on line 20 [28-Mar-2024 12:52:36 UTC] PHP Warning: session_start(): Failed to read session data: files (path: /var/cpanel/php/sessions/ea-php56) in /home/rgxb6tc5wk5q/public_html/golf/login/login.php on line 20 end of error. Sure would appreciate any help!! Please let me know if you need code. Charlie
  14. i recommend that you make a new file with the code necessary to load the phpmailer script and with your sendEmailNotification() function in it, setup some test data, and call the sendEmailNotification() function and get the email to work. once you get the email to work on its own, then make sure that your full code is actually calling the sendEmailNotification() function, by echoing/logging a value at the completion of the email code. you are performing a redirect right after the INSERT query. it's possible that the sms code will take enough time to make the curl request that the browser can abort the current request and halt code execution before your code gets to the email code. it's also possible that the curl code is throwing an error and your code never gets to the email code. any such redirect needs to be at the end of the post method form processing code, it should only occur if there are no user/validation errors, and it should be to the exact same URL of the current page to cause a get request for that page. here's a list of things that will simplify the code, making it easier to see what the code is trying to do - you should only catch and handle database exceptions for user recoverable errors, such as when inserting/updating duplicate user submitted data. for all other insert/update query error numbers, just rethrow the exception and let php handle it and for all other type of queries, let php catch and handle any database exception. for the INSERT query you should be catching and testing for a duplicate index error number. if an applicant can only register once, the applicant_id column should be defined as a unique index, so that only one record per applicant_id can be inserted. if an applicant can only register for a single exam_date_id, the combined applicant_id and exam_date_id columns need to be defined as a composite unique index. if you set the default fetch mode to assoc when you make the database connection, you won't have to specify it in each fetch statement. don't copy variables to other variables for nothing. just use the original variables that data is in.
  15. I have an admission application form, and I want an email and SMS notification to be sent to the applicant's email and phone upon successful registration. I have tried using the mail() function, but I am not receiving any email notifications at the recipient's email. I also tried using Gmail, but none of them are working. I used Composer to install the vendor autoload, but it is still not working. I don't know where the error is coming from. Below are the tables and the code: Table CREATE TABLE applicants ( id INT AUTO_INCREMENT PRIMARY KEY, application_id VARCHAR(20) UNIQUE, surname VARCHAR(100), othername VARCHAR(100), dob DATE, phone VARCHAR(20), email VARCHAR(100), lga VARCHAR(100), state_origin VARCHAR(100), current_school VARCHAR(100), current_class VARCHAR(50), proposed_class ENUM('Year 7 (JSS1)', 'Year 8 (JSS2)', 'Year 10 (SS1)', 'Year 11 (SS2)', 'Year 1 (PRY 1)', 'Year 2 (PRY 2)', 'Year 3 (PRY 3)', 'Year 4 (PRY 4)'), status VARCHAR(20) DEFAULT 'Pending' ); CREATE TABLE exam_dates ( id INT AUTO_INCREMENT PRIMARY KEY, exam_date DATE, type ENUM('Online', 'On-site'), is_past BOOLEAN DEFAULT FALSE ); CREATE TABLE exam_registrations ( id INT AUTO_INCREMENT PRIMARY KEY, applicant_id INT, exam_date_id INT, FOREIGN KEY (applicant_id) REFERENCES applicants(id), FOREIGN KEY (exam_date_id) REFERENCES exam_dates(id) ); ALTER TABLE applicants ADD registered_on DATETIME; PHP <?php session_start(); require_once('db_config.php'); //require_once(__DIR__ . '/../vendor/autoload.php'); require_once('vendor/autoload.php'); // Import PHPMailer classes into the global namespace use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; // Fetch available exam dates from the database try { $stmt = $pdo->query("SELECT * FROM exam_dates WHERE is_past = FALSE"); $exam_dates = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } // Check if the user is logged in as an applicant if (!isset($_SESSION['user_type']) || $_SESSION['user_type'] !== 'applicant') { header("Location: login.php"); exit(); } // Logout logic if (isset($_POST['logout'])) { session_destroy(); // Destroy all session data header("Location: login.php"); // Redirect to the login page exit(); } // Set the applicant_id from the applicants table try { $username = $_SESSION['username']; $stmt = $pdo->prepare("SELECT * FROM applicants WHERE application_id = ?"); $stmt->execute([$username]); $applicant = $stmt->fetch(PDO::FETCH_ASSOC); $_SESSION['applicant_id'] = $applicant['id']; $applicant_email = $applicant['email']; // Store the applicant's email address } catch(PDOException $e) { echo "Error: " . $e->getMessage(); exit(); } // Check if the applicant has already registered for an exam date try { $stmt = $pdo->prepare("SELECT * FROM exam_registrations WHERE applicant_id = ?"); $stmt->execute([$applicant['id']]); $registered_exam_dates = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } // Handle exam registration if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['exam_date'])) { // Check if the applicant has already registered for an exam date if (!empty($registered_exam_dates)) { //echo "You have already registered for an exam date."; exit(); } $applicant_id = $_SESSION['applicant_id']; $exam_date_id = $_POST['exam_date']; // Insert exam registration details into exam_registrations table try { $stmt = $pdo->prepare("INSERT INTO exam_registrations (applicant_id, exam_date_id) VALUES (?, ?)"); $stmt->execute([$applicant_id, $exam_date_id]); // Redirect to exam confirmation page or show success message header("Location: exam_confirmation.php"); // Send SMS to applicant $message = "Thank you for your application. Your username is: " . $applicant['application_id'] . " and Password is your surname."; $api_url = 'my api url'; $token = 'my token'; $sender = 'Olu'; $recipient = $applicant['phone']; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $api_url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array( 'token' => $token, 'sender' => $sender, 'to' => $recipient, 'message' => $message, ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo 'cURL Error #:' . $err; } else { echo 'SMS sent successfully.'; } // Send email notification to applicant using PHPMailer sendEmailNotification($applicant_email, $applicant['application_id'], $applicant['surname']); exit(); } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } } // Function to send email notification using PHPMailer function sendEmailNotification($recipientEmail, $applicationId, $surname) { // Instantiate PHPMailer $mail = new PHPMailer(true); try { // SMTP configuration (Gmail) $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'olu@gmail.com'; $mail->Password = 'mypassword'; $mail->SMTPSecure = 'tls'; $mail->Port = 587; // Email content $mail->setFrom('olu@gmail.com', 'My Schol'); $mail->addAddress($recipientEmail); $mail->Subject = 'Application Registration Confirmation'; $mail->isHTML(true); $mail->Body = "Dear $surname,<br><br>Thank you for your application at my Schol. Your username is: $applicationId and Password is your surname.<br><br>Best regards,<br>My Schol"; // Send email $mail->send(); echo 'Email sent successfully!'; } catch (Exception $e) { echo "Error: {$mail->ErrorInfo}"; } } ?> <!DOCTYPE html> <html> <head> <title>Applicant Dashboard</title> <script> // JavaScript function to display a popup function displayPopup() { alert("You have already registered for an exam date."); } </script> </head> <body> <h2>Welcome, <?php echo $applicant['surname']; ?></h2> <!-- Display applicant information --> <p>Applicant's Name: <?php echo $applicant['surname'] . ' ' . $applicant['othername']; ?></p> <p>Application ID: <?php echo $applicant['application_id']; ?></p> <p>Date of Birth: <?php echo $applicant['dob']; ?></p> <p>Phone: <?php echo $applicant['phone']; ?></p> <p>Email: <?php echo $applicant['email']; ?></p> <p>Local Government Area: <?php echo $applicant['lga']; ?></p> <p>State of Origin: <?php echo $applicant['state_origin']; ?></p> <p>Current School: <?php echo $applicant['current_school']; ?></p> <p>Current Class: <?php echo $applicant['current_class']; ?></p> <p>Proposed Class: <?php echo $applicant['proposed_class']; ?></p> <!-- Selected exam date --> <p>Selected Exam Date: <?php if (!empty($registered_exam_dates)) { $selected_exam_date_id = $registered_exam_dates[0]['exam_date_id']; foreach ($exam_dates as $date) { if ($date['id'] == $selected_exam_date_id) { echo date('F j, Y', strtotime($date['exam_date'])) . " (" . $date['type'] . ")"; break; } } } else { echo 'Not selected'; } ?> </p> <hr> <!-- Exam date selection --> <h3>Exam Date Selection</h3> <form id="exam_form" method="post"> <label for="exam_date">Select Exam Date:</label><br> <select id="exam_date" name="exam_date"> <?php foreach ($exam_dates as $date) : ?> <option value="<?php echo $date['id']; ?>"><?php echo $date['exam_date'] . " (" . $date['type'] . ")"; ?></option> <?php endforeach; ?> </select><br><br> <input type="button" value="Register for Exam" onclick="checkExamRegistration()"> <!--<input type="submit" value="Register for Exam">--> </form> <!-- Application status --> <h3>Application Status</h3> <p>Status: <?php echo $applicant['status']; ?></p> <!-- Logout form --> <form method="post"> <input type="submit" name="logout" value="Logout"> </form> <script> // Function to check if the applicant has already registered function checkExamRegistration() { <?php if (!empty($registered_exam_dates)): ?> displayPopup(); <?php else: ?> document.getElementById("exam_form").submit(); <?php endif; ?> } </script> </body> </html>
  16. Last week
  17. Visual Studio can be a powerful IDE for PHP development with the help of plugins and extensions. Below are the steps to set up PHP_CodeSniffer for coding standards and Xdebug for debugging with breakpoints in Visual Studio, along with some alternative tools: PHP_CodeSniffer Setup: PHP_CodeSniffer helps maintain coding standards in your project. You can integrate it into Visual Studio using the following steps: First, install PHP_CodeSniffer globally using Composer. Open your command line interface and run: composer global require "squizlabs/php_codesniffer=*" Next, you'll need to add PHP_CodeSniffer as an external tool in Visual Studio. Go to Tools > External Tools. Click on Add and fill in the following fields: Title: PHP_CodeSniffer Command: Enter the path to the phpcs.bat file. This can typically be found in C:\Users\YourUsername\AppData\Roaming\Composer\vendor\bin. Arguments: --standard=PSR2 $(ItemPath) Initial directory: $(ItemDir) Check the option for "Use Output window". Click OK to save. Now, you can use PHP_CodeSniffer by right-clicking on a PHP file in Solution Explorer, and then selecting PHP_CodeSniffer from the Tools menu. It will check your code against PSR2 coding standards. Best Regard Danish hafeez | QA Assistant ICTInnovations Xdebug Setup: Xdebug is a PHP extension that allows for debugging PHP scripts. Here's how you can set it up in Visual Studio: First, download and install Xdebug on your server. You can follow the instructions on the Xdebug website. Once installed, configure Xdebug in your php.ini file. Make sure to set xdebug.remote_enable=1 and xdebug.remote_autostart=1. In Visual Studio, you'll need to install the "PHP Debug" extension. Go to Extensions > Manage Extensions. Search for "PHP Debug" and install it. Configure PHP Debug extension: Go to Tools > Options. Navigate to PHP Tools > Debugging. Set the "Xdebug Port" to the port configured in your php.ini file (default is 9000). Click OK to save the settings. Now, you can set breakpoints in your PHP code and start debugging by pressing F5 or clicking on the Start Debugging button. Alternate Tools: If you find the setup process for PHP_CodeSniffer and Xdebug too complicated, or if you're looking for alternatives, you can consider the following: PHP Mess Detector (PHPMD): Similar to PHP_CodeSniffer, PHPMD focuses on detecting potential problems in your code. PHPCSFixer: This tool automatically fixes many coding standard violations reported by PHP_CodeSniffer. DBGp Proxy: An alternative to Xdebug for debugging PHP applications. Visual Studio Code: If you're open to using a different IDE, Visual Studio Code has excellent support for PHP development with extensions available for PHP_CodeSniffer and Xdebug integration. Choose the tools that best fit your requirements and preferences.
  18. foreach ($data as $cards) { $cards = json_decode($data['cards'], true); $count = sizeof($cards); $out = ''; if ($count == 4) { $size = "col-xl-3 col-md-6"; } else if ($count == 3) { $size = "col-xl-4 col-md-4"; } else if ($count == 2) { $size = "col-xl-6 col-md-6"; } else if ($count == 1) { $size = "col-12"; } foreach ($cards as $cardName => $cardDetails) { $icon_code = $icons[$cardDetails['Icon']]; $out .= "<div class='$size mb-3'> <div class='card editHeroCard' data-card='$cardName'> <div class='card-body'> <div class='text-center card-title'> <i class='$icon_code fa-2xl'></i> </div> <div class='card-text text-center my-3 fw-bold'>$cardDetails[Name]</div> <div class='card-text text-center'>$cardDetails[Paragraph]</div> </div> </div> <div class='handle text-center'>GRAB</div> </div>"; }
  19. I have a function that contains the following: foreach ($data as $cards => $row) { print_r($data); the data that is printed is as follows: Array ( [cards] => {"Card 1": {"This": "Something 1", "Paragraph": "This is the first card", "Icon": 562, "Order": 5}, "Card 2": {"This": "Something 2", "Paragraph": "This is the second card", "Icon": "559", "Order": 2}, "Card 3": {"This": "Somethihg 3", "Paragraph": "This is the third card", "Icon": "560", "Order": 3}, "Card 4": {"This": "Something 4", "Paragraph": "This is the fourth card", "Icon": "561", "Order": 4}} ) I want to "get" "Card 1", "Card 2"... How in a loop can i access this part of the array. I have tried print_r $data, $cards and $row and none of them give me what i need. When i try and use [0] i just get the first letter.
  20. I have been looking at documentation and it seems that something like this is the route that i need to take - but i am getting no results in php my admin when running this query. SELECT portal_content_json from portal_content where JSON_SEARCH( portal_content_json, 'all', 2, Null, ' $[*]."Hero Cards[*]"."Order"') IS NOT NULL;
  21. your current approach is flawed because you're updating the IDs in a loop without considering the existing IDs in the database. Also, the update query inside the loop doesn't seem to be properly updating the IDs. <?php echo "<table class='tabela_dados' border='1'> <tr> <td>ID</td> <td>Nome Empresa</td> <td>Responsável</td> <td>Telefone 1</td> <td>Telefone 2</td> <td>E-mail 1</td> <td>E-mail 2</td> <td>Endereço</td> <td>CEP</td> <td>Bairro</td> <td>AÇÃO 1</td> <td>AÇÃO 2</td> </tr> "; $sql = "SELECT * FROM usuarios_dados WHERE Usuario='$usuario'"; $result = $conn->query($sql); if ($result->num_rows > 0) { $Novo_ID = 1; while ($row = $result->fetch_assoc()) { // Update the ID in the database $old_ID = $row['ID']; $sql_update = "UPDATE usuarios_dados SET ID='$Novo_ID' WHERE ID='$old_ID'"; $conn->query($sql_update); // Output the row with the updated ID echo "<tr> <td>$Novo_ID</td> <td>{$row['Nome_Empresa']}</td> <td>{$row['Responsavel']}</td> <td>{$row['Telefone_1']}</td> <td>{$row['Telefone_2']}</td> <td>{$row['Email_1']}</td> <td>{$row['Email_2']}</td> <td>{$row['Endereço']}</td> <td>{$row['CEP']}</td> <td>{$row['Bairro']}</td> <td> <form method='post' action='Editar_Dados.php'> <input type='hidden' name='usuario' value='$usuario'> <input type='hidden' name='senha' value='$senha'> <input type='hidden' name='ID' value='$Novo_ID'> <input type='submit' style='padding: 10px;' value='EDITAR'> </form> </td> <td> <form method='post' action='Deletar_Dados.php'> <input type='hidden' name='usuario' value='$usuario'> <input type='hidden' name='senha' value='$senha'> <input type='hidden' name='ID' value='$Novo_ID'> <input type='submit' style='padding: 10px;' value='DELETAR'> </form> </td> </tr>"; $Novo_ID++; } } else { echo "0 results"; } echo "</table>"; $conn->close(); ?> This code will assign sequential IDs starting from 1 to each row in the database table while displaying the data in the HTML table. Make sure to replace $usuario and $senha with appropriate variables if they are defined elsewhere in your code. Best Regard Danish Hafeez | QA Assistant ICTInnovations
  22. welcome to phpfreaks i hope you will get proper help from this forum and you will also help other if you will understand questions. Best Regard Danish hafeez | QA Assistant ICTInnovations
  23. Earlier
  24. You need to output a row number, not the actual id. One way is to increment a $rowno variable each time you output a row of your query results and output that. Alternatively, there are a couple of ways you can do it with a single query. Test data TABLE: reindeer +----+---------+ | id | name | +----+---------+ | 1 | Comet | | 3 | Cupid | | 4 | Dasher | | 6 | Vixen | | 8 | Prancer | | 10 | Dancer | | 15 | Donner | | 16 | Blitzen | +----+---------+ Using an SQL variable SELECT @rowno := @rowno+1 as rowno , name , id FROM reindeer JOIN (SELECT @rowno := 0) as init ORDER BY name; Using the ROW_NUMBER() window function (MariaDB v11 or MySql v8) SELECT ROW_NUMBER() OVER (order by name) as rowno , name , id FROM reindeer ORDER BY name; Both the above output +-------+---------+------+ | rowno | name | id | +-------+---------+------+ | 1 | Blitzen | 16 | | 2 | Comet | 1 | | 3 | Cupid | 3 | | 4 | Dancer | 10 | | 5 | Dasher | 4 | | 6 | Donner | 15 | | 7 | Prancer | 8 | | 8 | Vixen | 6 | +-------+---------+------+
  25. your initial post is meaningless. I-m trying to do the following !! (I THINK YOU MEANT TO write I'm instead of I-m. At least I hope you do.) What is the following? You don't say what it is you are trying to do. Listing data in the table !! Listing data is a normal procedure for programmers to accomplish. What is the problem? You don't say. I would like....if the list has 4 rows..whetever the ID list is..make the ID list 1 2 3 4 !! Example.....if have a list with ID 1 3 3...make stay 1 2 3 !! If you have an "ID" of some sort in your database then it should not be altered and it should be UNIQUE. Yet - you are saying that when displayed you want the "ID" to be modified to show your records with a new consecutive list of ids that are not what your database should be showing. WHY WOULD ANYONE DO THAT? Maybe you need to explain in English what it is you are trying to do.
  26. This is great - i can confirm that it did what i needed so thanks for that. Now i just need to workout how to select by order Number in order to update the values when the data is edited.
  27. Record IDs ... should be unique. should never be changed should never be reallocated Breaking those rules destroys the integrity of your database. And as for you update query, what is the point of setting the id to X where the id = X. That is like you changing your username on this forum to "Legendary_003"
  1. Load more activity
×
×
  • 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.