Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Screen.rows, screen.columns, screen.capacity look like derived values to me - you can get that info from the seats for each screen. booking.ticket_date is no longer required - duplicates the screening.screen_on value. However, you need to consider the payment process. What if a user books seats and their payment is subsequntly declined? You would need to know who made the booking. Perhaps make the booking.ticket date an automatic timestamp and, on booking, set a status "payment pending". Set status to "paid" on successful payment. Periodically remove pending payments older than X minutes to release the seats for sale again.
  2. Are you sure "index.php" is in your root folder?
  3. @gizmola With my model you would need to bring the ticket date into the equation SELECT s.id, s.row, s.seat_no FROM seat s LEFT JOIN booking b ON b.seat_id = s.id AND b.screening_id = 35 AND B.ticket_date = '2024-01-03' -- also required WHERE s.screen_id = 1 AND b.id IS NULL; As it is, a screening record states that the movie will be screened at time T each day between X and Y. On reflection, although requiring more rows, it would be better to have a screening record for every individual screening, giving... then your query would work as it is. Alternatively, to get vacant seats for a screening (and only requiring the screening id as input - if the screening id is known then the screen id is also known) you could SELECT s.id, s.row, s.seat_no FROM screening sg JOIN seat s ON sg.screen_id = s.screen_id LEFT JOIN booking b ON b.screening_id = sg.id AND b.seat_id = s.id WHERE sg.id = 35 AND b.id IS NULL
  4. What format is $_POST['date']? When binding the query params, $date is a string value - you specified "d" (double) and not "s" (string). Please use the code button "<>" when posting code in future.
  5. By default, div widths are 100% [edit]... PS you could add some css of your own in the style section of the head. <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap demo</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> </head> <style type='text/css'> .alert-success { width: 25%; text-align: center; } </style> <body> <h1>Hello, world!</h1> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> <?php echo "<div class='alert alert-success' role='alert'>this is my_message</div>"; ?> </body> </html>
  6. Have you tried it?
  7. The above code is invalid php syntax. That's why there is no output. Try <?php echo "<div style='color: green;'>my_message</div>"; echo "my error"; echo 'my error 2'; ?>
  8. P.S. You should be using a prepared statement to avoid SQL injection $stmt = $conn->prepare("INSERT INTO user (name, email, phone) VALUES (?, ?, ?); $stmt->bind_param('sss', $name, $email, $phone); $stmt->execute(); And, to make life easier for yourself, switch to PDO instead of mysqli.
  9. Try changing $sql= "INSERT INTO 'user' ('name', 'email', 'phone') VALUES ('$name', '$email', '$phone')"; to $sql= "INSERT INTO `user` (`name`, `email`, `phone`) VALUES ('$name', '$email', '$phone')"; Backticks, not single quotes (but unnecessary they are not reserved words)
  10. I hope I am wrong on this, but my theory is that if we total all the values in your query output "Total" column to get an overall total then that should equal the total of all billing.gross_amount values for sales_office 801. mysql> SELECT format(sum(x.Total),0) as grandTotal -> FROM ( -> SELECT sum(a.gross_amount) AS Total, b.DistributionChannelDesp AS Department, c.branchName AS Branch, -> d.grpName AS DepartmentGroup, e.equiSubName AS Equipment, g.mgName AS Material -> FROM sbms.billing AS a -> INNER JOIN sbms.department_code AS b ON b.DChannel = a.dchannel -> INNER JOIN sbms.branch AS c ON c.branchcode = a.sales_office -> INNER JOIN sbms.dept_group AS d ON d.grpID = b.grpID -> INNER JOIN sbms.equipmentsubcategory AS e ON e.eqipSubCode = a.division -> INNER JOIN sbms.materialsubgroup AS f ON f.mgsubNumber = a.material -> INNER JOIN sbms.materialgroup AS g ON g.mgID = f.mgID -> WHERE a.sales_office='801' -> GROUP BY b.DistributionChannelDesp, d.grpID, e.equiSubName, g.mgID -> ) x ; +---------------+ | grandTotal | +---------------+ | 1,998,441,259 | +---------------+ 1 row in set (1.47 sec) mysql> SELECT format(sum(a.gross_amount),0) AS Total_801 -> FROM billing a -> WHERE sales_office='801'; +---------------+ | Total_801 | +---------------+ | 6,195,206,276 | +---------------+ 1 row in set (0.74 sec) As you can see there is a minor discrepancy of around 4 billion. (4,196,765,017 to be precise).
  11. Should be faster than that mysql> SELECT sum(a.gross_amount) AS Total, b.DistributionChannelDesp AS Department, c.branchName AS Branch, -> d.grpName AS DepartmentGroup, e.equiSubName AS Equipment, g.mgName AS Material -> FROM sbms.billing AS a -> INNER JOIN sbms.department_code AS b ON b.DChannel = a.dchannel -> INNER JOIN sbms.branch AS c ON c.branchcode = a.sales_office -> INNER JOIN sbms.dept_group AS d ON d.grpID = b.grpID -> INNER JOIN sbms.equipmentsubcategory AS e ON e.eqipSubCode = a.division -> INNER JOIN sbms.materialsubgroup AS f ON f.mgsubNumber = a.material -> INNER JOIN sbms.materialgroup AS g ON g.mgID = f.mgID -> WHERE a.sales_office='801' -> GROUP BY b.DistributionChannelDesp, d.grpID, e.equiSubName, g.mgID; +--------------------+---------------------+---------+------------------+----------------------+------------------------------------------+ | Total | Department | Branch | DepartmentGroup | Equipment | Material | +--------------------+---------------------+---------+------------------+----------------------+------------------------------------------+ | 16368308 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | OMC Charges | | 2549368 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | Service Chgs-Repair work @ customer site | | 4217060 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | Service Charges for Plant Installation | | 3567304 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | Service Charges for Calibration | | 1038001 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | Machinery Software Updation Charges | | 968000 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | Annual Maintenance Contract Charges | | 400000 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | Equipment Hiring Charges | | 201500.3 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | Schwing Cloud Solns - Batching Plant | | 60000 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | AUTOMATION SERVICES | | 26502.93 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | Wear Parts | | 771.47 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | Consumables | | 78795 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | Electrical Parts | | 45743.13 | Cust. Service | CHENNAI | Domestic-Parts | Batch plants | Other Parts | | 739820 | Cust. Service | CHENNAI | Domestic-Parts | Excavator | OMC Charges | ... etc 495 rows in set (1.55 sec)
  12. Easiest is with mysql workbench. Expand the table and columns Right-click coumn name and select "Create index" Click "Create"
  13. That is nothing like the solution I suggested. In fact you ignored just about everything in my posts. If two people run your code simultaneously they will both think it is safe to add the same number and you are back where you started.
  14. Put indexes on the columns that you are joining on. This speeds things up considerably as it doesn't have to read the entire joined table to find a match. As you can see... The fields you you are joining on should be of the same type. You are joining on columns defined as int in one table and varchar in the other.
  15. Forget my last reply then. That relied on there being a single connection. You are going to have to do it the hard way in your code rather than letting the mysql handle it. Only try the other 2 inserts if the first does not fails with a duplicate error.
  16. If they are 3 databases on the same server all with the same usernames and passwords then you only need a single connection. A connection is to a server and not to to a database. Try this, so that if any of the inserts fail the other two are cancelled. // make connection to DB server // call mysql_report so that all errors are reported as execptions // this saves you from having to check every mysql function call to see if it worked or not mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $conn = mysqli_connect($servernameS, $usernameS, $passwordS, $databaseS); // NOTE - single connection $conn if ($_SERVER['REQUEST_METHOD']=='POST') { $link = trim($_POST['link']); if ($link != '') { try { $conn->begin_transaction(); $stmt1 = $conn->prepare("INSERT INTO DB1.nametable (link) VALUES (?)"); // define which DB to use - DB1, DB2 or DB3 $stmt2 = $conn->prepare("INSERT INTO DB2.nametable (link) VALUES (?)"); $stmt3 = $conn->prepare("INSERT INTO DB2.nametable (link) VALUES (?)"); $stmt1->bind_param('i', $link); $stm1t->execute(); $stmt2->bind_param('i', $link); $stmt2->execute(); $stmt3->bind_param('i', $link); $stmt3->execute(); $conn->commit(); } catch(mysqli_sql_exception $e) { $conn->rollback(); if ($e->getCode() == 1062) { echo "Sorry, this was already sent"; } else { throw $e; } } } }
  17. The code you post doesn't insert anything, anywhere. All is does is define the content of the string $sql. Are all three databases on the same server (host) or are you connecting to three separate hosts?
  18. You need to implement the method I gave you in PHP. For instance, executing that sql query would be a good move.
  19. Your db connection code needs adjustment //make connection to DB server // call mysql_report so that all errors are reported as execptions // this saves you from having to check every mysql function call to see if it worked or not mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $connS = mysqli_connect($servernameS, $usernameS, $passwordS, $databaseS); Now you can remove your code which checks for errors and replace your insert query with the coed I gave you
  20. Use try .. catch, for example // pseudocode - in case you didn't notice)... try { insert the record // attemp the insert } catch (exception) { if (exception error code is 1062) { // error detected - was it a duplicate? output your duplicate record message // yes it was so report it } else { throw (exception) // no it wasn't so let php handle the exception } }
  21. Something like... <!DOCTYPE html> <html lang="en"> <head> <title>Example</title> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> $(function() { $(".form-button").click(function(e) { e.preventDefault() // stop button from submitting the form alert("Button " + $(this).val() + " clicked") }) }) </script> <style type='text/css'> #myform { padding: 30px; width: 330px; margin: 20px auto; border: 1px solid blue; text-align: center; } </style> </head> <body> <form id='myform' > <button class='form-button' name='form-button' value='1'>Button 1</button> <button class='form-button' name='form-button' value='2'>Button 2</button> <button class='form-button' name='form-button' value='3'>Button 3</button> <br><br> <button>Submit</button> </form> </body> </html>
  22. The relevant link was in my reply... which linked to ... https://www.php.net/mysqli_query
  23. Following the link to the required page in the manual that I provided would be a start.
×
×
  • 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.