Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Your code was if $prod is in the array loop through the array and output each value endif As your values are 10, 20 and 30 then the output of "102030" is doing exactly what you asked it to do. Why don't you tell us what you need - we aren't psychics.
  2. PS Your processing sequence is FUBAR. You should Handle ajax requests - any output in an ajax call is returned in the response, so you need to process and exit asap Handle POST processing - then after updating db reload the page with a location header and exit. Handle GET processing and other processing required for page output. HTML
  3. Page loads and the <script> at bottom of page runs, defining the .delButton click handler. User clicks "Manage" button and a delButton is created, but the handler has already been defined When a handler is defined for a class it is attached to existing members of that class. Your delButton does not exist when the page is initially loaded.
  4. When does the $('.delButton').click(function () run to define what happens when it is clicked? Is it before the delButton has been created? If the answer to the second is "Yes" then the button object will not receive the click handler.
  5. Now you have added an input field to edit the comment you need to add the comment column to the database update. At present it only updates status in your above code..
  6. in_array() checks if a value exists in an array. You are looking for a key. if (isset($array1[$prod]) )
  7. You cannot just blindly copy/paste without thought about context and what it is doing. Lines 35 to 45 should be <tr> <td>{$row['id']}</td> <td>{$row['details']}</td> <td>{$row['location']}</td> <td>{$row['status']}</td> <td><textarea name='comment' cols='50' rows='5'>{$row['comment']}</textarea></td> <td><button name='status' value='Approved' class='w3-button w3-green'>Approve</button></td> <td><button name='status' value='Rejected' class='w3-button w3-red'>Reject</button></td> </tr>
  8. Then add one, for example <form method='post'> <textarea name='comment' cols='50' rows='5'><?=$comment?></textarea> <button name='status' class='w3-button w3-green' value='Approved'>Approve</button> <button name='status' class='w3-button w3-red' value='Rejected'>Reject</button> </form>
  9. The presence of the state mileage data would be sufficient for most people to indicate when it's there. The mileage data itself is your flag. And the error checking...?
  10. You should be normalizing your data and put the miles in a separate table +---------------------+ | invoice | +---------------------+ | inv_id (PK) | | order_no (UQ) |-----+ | order_date | | +---------------------+ | +----------------------+ | | state_miles | | +----------------------+ | | state_miles_id (PK) | +-----<| order_no (FK) | | state | | miles | +----------------------+ Are you getting any pdo errors? - I don't see you checking for any (have you set the ERRMODE attribute when connecting?) [edit] PS Why are you getting the last insert id before you have executed the insert? Why do you need the last insert id? Why is there a subsequent update immediately after the insert?
  11. Works fine for me mysql> select * from pup; +----+-------+--------+---------------------+ | id | name | amount | transaction_date | +----+-------+--------+---------------------+ | 1 | Curly | 10.00 | 2020-01-01 10:00:00 | | 2 | Larry | 20.00 | 2020-01-15 12:30:00 | | 3 | Mo | 15.00 | 2020-02-01 09:00:00 | | 4 | Peter | -5.00 | 2020-02-01 10:30:00 | | 5 | Paul | 10.00 | 2020-02-02 11:30:00 | | 6 | Mary | 5.00 | 2020-02-02 12:15:00 | +----+-------+--------+---------------------+ 6 rows in set (0.00 sec) mysql> select MAX(id) as maxid FROM pup; +-------+ | maxid | +-------+ | 6 | +-------+ 1 row in set (0.01 sec) or <?php $res = $conn->query("SELECT MAX(id) as maxid FROM pup"); $row = $res->fetch_assoc(); echo $row['maxid']; //--> 6 ?>
  12. You have an "undefined variable (out) error where you are concatenating. ajax call "two" is triggered when something with class="delButton" is clicked. I can find no reference to delButton in your html
  13. Your "view details" link will be <a href="details.php?id=$id">View full details</a> so that when details.php loads the id of the selected record will be in GET['id']. Your query is then SELECT details , location, , date , time , status , comment FROM tablename WHERE id = ? Lay out the results as you want
  14. The code will be pretty much the same as this. The exceptions will be No update processing required No " WHERE status = 'Pending' " Select all columns (ie date and time also)
  15. Use hidden form fields. When you first load the form data, set their values. As the values change in the JS code, keep the hidden fields updated too.
  16. Replace my comment with $conn = mysqli_connect("localhost","root", "","update");
  17. When you find you have a lot of repetition of similar code, consider the use of an array and iteration.
  18. I had something like this in mind Example code: <?php /* CONNECT TO DB SERVER HERE */ // // Check if data was posted for processing // if ($_SERVER['REQUEST_METHOD']=='POST') { $stmt = $conn->prepare("UPDATE ronel SET status = ? WHERE id = ? "); $stmt->bind_param('si', $_POST['status'], $_POST['id']); $stmt->execute(); header("Location: #"); // reload the page exit; } $pendingRecs = ''; $res = $conn->query("SELECT id , details , location , status , comment FROM ronel WHERE status = 'Pending' ORDER BY date, time "); if ($row = $res->fetch_assoc()) { do { $pendingRecs .= " <form method='post'> <input type='hidden' name='id' value='{$row['id']}'> <tr> <td>{$row['id']}</td> <td>{$row['details']}</td> <td>{$row['location']}</td> <td>{$row['status']}</td> <td>{$row['comment']}</td> <td><button name='status' value='Approved' class='w3-button w3-green'>Approve</button></td> <td><button name='status' value='Rejected' class='w3-button w3-red'>Reject</button></td> </tr> </form> "; } while ($row = $res->fetch_assoc()); } else { $pendingRecs = "<tr><td colspan='7'>No Pending records</td></tr>" ; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Dashboard</title> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <style type='text/css'> body { font-family: calibri, sans; font-size: 12pt; } </style> </head> <body> <header class="w3-container w3-orange w3-padding w3-center"> <h2>Dashboard</h2> </header> <div class="w3-content w3-padding"> <table class="w3-table w3-bordered"> <tr style="background-color:#E4EBC5; color:orangered;"> <th>ID</th> <th>Details</th> <th>Location</th> <th>Status</th> <th>Comment</th> <th colspan="2">Action</th> </tr> <?=$pendingRecs?> </table> </div> </body> </html> TABLE: ronel +----------+---------------------------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+---------------------------------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | | auto_increment | | details | varchar(45) | YES | | | | | location | varchar(45) | YES | | | | | date | date | YES | | | | | time | time | YES | | | | | status | enum('Pending','Approved','Rejected') | NO | | Pending | | | comment | varchar(250) | YES | | | | +----------+---------------------------------------+------+-----+---------+----------------+
  19. Change the select query to add a where clause so you only select pending records. On each output row, add Approve and Reject buttons with references to the record's id. A couple of comments on your code: Use prepared statements, don't put values directly into the query string. the "for=" attributes in your labels should contain the unique id of the associated input element.
  20. Do you mean "describe persons"? NM - I see they do the same thing mysql> describe pup; +------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(20) | YES | | NULL | | | amount | decimal(8,2) | YES | | NULL | | | transaction_date | datetime | YES | | NULL | | +------------------+--------------+------+-----+---------+----------------+ 4 rows in set (0.01 sec) mysql> explain pup; +------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(20) | YES | | NULL | | | amount | decimal(8,2) | YES | | NULL | | | transaction_date | datetime | YES | | NULL | | +------------------+--------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec) I only ever used explain with queries, not tables.
  21. That has nothing to do with your problem of finding the MAX(id), although it does show that you are capable, sometimes, of processing the results of a query.
  22. Which versions don't? I haven't come across one.
  23. All those lines do is assign values to $sql string variable. Do you expect that will magically execute the SQL query and return the result?
  24. If you show us some code we might be able to tell you.
×
×
  • 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.