Jump to content

Barand

Moderators
  • Posts

    24,607
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. Specify the number of dec places in your call to number_format()
  2. That expression returns whichever is the smaller number - the count or 49. So if the count is, say, 40, then it returns 40. If it is anything over 49 it returns 49 (100%) as that is the smaller number.
  3. $totalgoal2 = number_format(min($num_rows['count'], 49)/49*100);
  4. Given that the query isn't syntactically correct and couldn't run, there is no way I'm attempting a solution without knowing the data and the structure of the data. So how about giving us some needed context.
  5. Output the results into an HTML table Put each result row in a new table <tr> row. Put each column into a table <td> cell. EG <?php // CONNECT TO DB HERE $sql = "SELECT animal_type , animal_breed , colour , owner_name , address , telephone , mobile , email , offence , offence_date , offence_location , case_status , case_ref , action_required , action_taken , microchipped , microchip_number , aggressive , dangerous , lost , date_lost , location_lost , stolen , date_stolen , location_stolen , found, date_found , location_found , other_information FROM `animals` -- WHERE 1 (utterly useless, just leave it out) "; //------------------------------------------------------------------------------ // I find this function useful for testing // queries when I haven't got MySql Workbench open function query2HTML($db, $sql) { $output = "<table border='1'>\n"; // Query the database $result = $db->query($sql); if ($result->num_rows == 0) return "No matching records"; // get the first row and display headings $row = $result->fetch_assoc(); $output .= "<tr><th>" . join('</th><th>', array_keys($row)) . "</th></tr>\n"; // display the data do { $output .= "<tr><td>" . join('</td><td>', $row) . "</td></tr>\n"; } while ($row = $result->fetch_assoc()); $output .= "</table>\n"; return $output; } ?> <!DOCTYPE html> <html lang='en'> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="generator" content="PhpED 19.5 (Build 19523, 64bit)"> <title>Example</title> <meta name="author" content="Barand"> <meta name="creation-date" content="04/09/2022"> <style type='text/css'> table { border-collapse: collapse; margin: 20px auto; width: 95%; } td, th { padding: 4px 8px; } th { background-color: #ccc; } </style> </head> <body> <?= query2html($conn, $sql) ?> </body> </html>
  6. He has. A query selects all records for which the WHERE expression evaluates to "true". As "1" is true for all records, they have specified that all records are selected.
  7. Example data TABLE: client TABLE: project +----+-----------+----------+ +----+---------------+-----------+------------+ | id | firstname | lastname | | id | project_name | client_id | start_date | +----+-----------+----------+ +----+---------------+-----------+------------+ | 1 | Scott | Chegg | | 1 | Project Alpha | 4 | 2022-12-01 | | 2 | Laura | Norder | | 2 | Proect Beta | 2 | 2023-01-15 | | 3 | Tom | DiCanari | | 3 | Project Gamma | 4 | 2023-03-01 | | 4 | S | Tonin | | 4 | Project Delta | 1 | 2023-03-20 | +----+-----------+----------+ +----+---------------+-----------+------------+ Query SELECT project_name , start_date , CONCAT(c.firstname, ' ', c.lastname) as client FROM project p JOIN client c ON p.client_id = c.id ORDER BY client, start_date; +---------------+------------+--------------+ | project_name | start_date | client | +---------------+------------+--------------+ | Proect Beta | 2023-01-15 | Laura Norder | | Project Alpha | 2022-12-01 | S Tonin | | Project Gamma | 2023-03-01 | S Tonin | | Project Delta | 2023-03-20 | Scott Chegg | +---------------+------------+--------------+ Now change the first name of client 4 and re-query UPDATE client SET firstname = 'Sarah' WHERE id = 4; SELECT project_name , start_date , CONCAT(c.firstname, ' ', c.lastname) as client FROM project p JOIN client c ON p.client_id = c.id ORDER BY client, start_date; +---------------+------------+--------------+ | project_name | start_date | client | +---------------+------------+--------------+ | Proect Beta | 2023-01-15 | Laura Norder | | Project Alpha | 2022-12-01 | Sarah Tonin | | Project Gamma | 2023-03-01 | Sarah Tonin | | Project Delta | 2023-03-20 | Scott Chegg | +---------------+------------+--------------+
  8. Data like names should be stored in one place only in a database. In this case, the only place the client name should be stored is in the "client" table. Other tables related to the client, such as "project" should contain the id of the id of the related client, When you query the project table you then JOIN to the client table using the client id. This way, a change in one place is all that is required. Databases should be correctly designed using a process of normalization - Google it.
  9. On your "previous page" you are populating $_SESSION['nik'] from $_POST['nik']. Are you sure 'nik' value was posted to that page? If not , $_SESSION['nik'] will be empty. Check the values in your $_SESSION. echo '<pre>' . print_r($_SESSION, true) . '</pre>';
  10. <?php require_once('kaynak/baglan.php'); session_start(); ?> <!DOCTYPE html> <html lang="tr"> <head> <title>Sayfanız - Hoşgeldiniz</title> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="kaynak/style.css"> </head> <body> <div id="ana"> <h1><?php echo $_SESSION['nik']; ?> Üye giriş sayfasına hoşgeldiniz</h1><br> </div> </body> </html>
  11. echo $_SESSION['nik']; ... does it. Forget about the POSTed values - there aren't any being sent.
  12. If you put it into $_SESSION['nik'] in the previous page, it will still be there. That previous page isn;t posting any data.
  13. It apparently hasn't reached this page or you woudn't be getting the error. How are you sending it?
  14. Has data been posted to that page at the time of the error? Check for posted data before trying to process it if ($_SERVER['REQUEST_METHOD']=='POST') { // here you can process posted data }
  15. It looks like it expects that code to be in "index.php". The posted data will be sent to that file (itself) If you remove action="index.php" you can call your php file anything and, without the action, it will call itself.
  16. Remember that only check checkboxes are posted, so the kth checkbox isn't necessarily the kth other items I'd use the id as index for the post array, for example... <input type='text' name='prod_qty[$prod_id]' value='<?= $prod_qty ?>' hidden>
  17. Probably works because mysql is more relaxed than the standard dictates
  18. Your query failed, so $result contains false and not a result object. Put this code before your call to nysql_connect... mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); ... it won't stop it failing but it will tell you why.
  19. You group by whatever you want to aggregate by. If you want total monthly sales, say, then you'd have something like SELECT YEAR(sales_date) as year , MONTH(sales_date) as month , SUM(sales_amount) as total FROM sales GROUP BY year, month If you wanted customer totals SELECT customer_id , SUM(sales_amount) as total FROM sales GROUP BY customer_id Neither customer_id nor sales_date is the primary key of the sales table.
  20. And what erroneous logic path leads you to that conclusion? As stated above - to prevent the inclusion of meaningless values in results. https://dev.mysql.com/doc/refman/8.0/en/group-by-handling.html
  21. An employee can have many orderid's. When you group by employee you get one row per employee and, therefore, only one of the orderid values would be shown. As this could be from any of the many orders its specific value is meaningless. On the other hand, gouping by orderid means there will be a unique employee. In standared SQL, the rule is enforced that only columns in the group by clause, or that are being aggregated, can be selected.
  22. yet also Good luck with that.
  23. Very unlikely. The tables only existed for the few microseconds it tok to run the script and was gone before the user viewed the results on the client.
×
×
  • 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.