Jump to content

Barand

Moderators
  • Posts

    24,303
  • Joined

  • Last visited

  • Days Won

    792

Everything posted by Barand

  1. 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'; ?>
  2. 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.
  3. 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)
  4. 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).
  5. 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)
  6. Easiest is with mysql workbench. Expand the table and columns Right-click coumn name and select "Create index" Click "Create"
  7. 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.
  8. 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.
  9. 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.
  10. 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; } } } }
  11. 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?
  12. You need to implement the method I gave you in PHP. For instance, executing that sql query would be a good move.
  13. 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
  14. 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 } }
  15. 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>
  16. The relevant link was in my reply... which linked to ... https://www.php.net/mysqli_query
  17. Following the link to the required page in the manual that I provided would be a start.
  18. RTFM mysqli_query() requires 2 arguments. There is more to switching from mysql_xxx() to mysqli_xxx() than just adding an "i". They are completely different animals.
  19. Is this the effect you are looking for? <head> <style type='text/css'> .curved-bottom { clip-path: ellipse(100% 60% at 50% 40%); background-color: #FFFF00; color: black; } .w3-row { background-color: black; color: white; } .w3-col { padding: 50px 0; text-align: center; } </style> </head> <body> <div class='w3-row'> <div class='w3-col m12 curved-bottom'> I have a curvy bottom </div> </div> <div class='w3-row'> <div class='w3-col m12'> I'm a straight guy </div> </div> </body>
  20. The only MyIsam-only functionality that I can think of is the ability to have a compound primary key EG PRIMARY KEY (year, number) where the 2nd part auto_increments within the first part, so if you have CREATE TABLE `test1` ( `year` int(11) NOT NULL, `number` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`year`,`number`) ) ENGINE=MyISAM ; mysql> select * from test1; +------+--------+ | year | number | +------+--------+ | 2022 | 1 | | 2022 | 2 | +------+--------+ mysql> insert into test1 (year) values (2022), (2022), (2023), (2023), (2024); mysql> select * from test1; +------+--------+ | year | number | +------+--------+ | 2022 | 1 | | 2022 | 2 | | 2022 | 3 | | 2022 | 4 | | 2023 | 1 | | 2023 | 2 | | 2024 | 1 | +------+--------+
  21. There is definitely an echo in here. @Moorcam WRONG! What about UPDATE and DELETE queries?
  22. Write it as a CLI script and use a CRON job to run it as frequently as required
  23. Then try running it when it isn't December or before 6am.
×
×
  • 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.