Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Check phpinfo() output to ensure you are editing the php.ini file that is actually being used. If it is the right one, check you really have the extension file and in the right folder. edit... PS Check you have PDO available - you'll be better off using that than mysqli.
  2. Example: My customer table contains these columns Columnss ------------- syncroid State Postcode id CompanyName City Address and I want to exclude id and syncroid from the dropdown list. <?php $res = $pdo->query("SELECT column_name FROM information_schema.Columns WHERE table_schema = 'db1' AND table_name = 'customer' ORDER BY column_name DESC"); $result = $res->fetchAll(PDO::FETCH_COLUMN); // define unwanted column names $exclude = ['id', 'syncroid']; // remove them $columns = array_diff($result, $exclude); ?> <select name='up_column' id='up_column'> <?php foreach ($columns as $col) { echo "<option>$col</option>\n"; } ?> </select> DROPDOWN...
  3. Once your page hits the browser there is nothing php can do. Any further client-side processing will require javascript. When page has loaded, set a timer ( see setTimeout() ) to initiate a process which hides your loading bar.
  4. You have already left it too long, but the longer you put it off the worse it will get. There are definite advantages to upgrading with new features having been added (both in PHP 8 and MySQL 8). The downside is your database processing will need to change. I'd also strongly recommend you use PDO rather than switching to mysqli (There is more involved than just adding an "I" to the function calls). How much extra coding will need changing will depend on how you coded in the past. For example, PHP8 is stricter on variable typing. EG <?php $a = ''; $b = 5; echo $a + $b; You probably get away with that at the moment , the '' being silently converted to '0', but with v8 you get PHP Fatal error: Uncaught TypeError: Unsupported operand types: string + int in C:\inetpub\wwwroot\test.php:4 Note that $a = '0' will work as it is convertible to int 0.
  5. First, click on the error notification and sort out the error. Then try again.
  6. Select "Developer tools" in browser menu Open network tab. Instigate the AJAX request When ajax call appears in network window, click on it Select response tab to response or request tab to see request
  7. Have you checked your network responses in your browser's developr tools?
  8. Unchecked checkboxes are not posted. I prefer to use a the null coalescing operator (??) when handling checkboxes EG $Bold = $_POST['Bold'] ?? 0; //if not set, default to '0'
  9. See https://www.php.net/manual/en/features.file-upload.php
  10. <style type='text/css'> .lr-border { display: inline-block; border-left: 3px solid gray; border-right: 3px solid gray; padding: 0 8px; margin: 30px 10px; } </style> <div class='lr-border'> Are you wanting something like this? </div> <br> <div class='lr-border'> ( where the width adjusts automatically with the text length ) </div>
  11. ... or get a larger monitor
  12. In your profile page, click in the top section of the page
  13. Of course you should create a table for the students' answers, mainly because it gives an audit trail for the student's grade and provides a historical record of their past performance. (And if every student gave the same wrong answer you have evidence of poor teacher performance or cheating in the exam )
  14. 25 echo dechex(ord('%')); // 25 echo chr(0x25); // %
  15. Welcome. I hope you enjoy the journey.
  16. I am not prepared to do any more guessing without the data that is being used. Whether your code and query is wrong, and why, depends on the data is is used with.
  17. You need to escape the backslash REPLACE(TextField, '\\n', '<br>') Example SELECT title FROM project WHERE id = 2; +----------------------+ | title | +----------------------+ | Project \n number 2 | +----------------------+ SELECT REPLACE(title, '\\n', '<br>') FROM project WHERE id = 2; +-------------------------------+ | REPLACE(title, '\\n', '<br>') | +-------------------------------+ | Project <br> number 2 | +-------------------------------+ Now you can worry about why your update process is writing two separate characters instead of a single linefeed.
  18. It looks as though it is two separate characters and not a linefeed character (linefeed = 0A) w e c h a r t e r e d a \ n f i s h i n g t r i p . 77 65 20 63 68 61 72 74 65 72 65 64 20 61 20 5C 6E 20 66 69 73 68 69 6E 67 20 74 72 69 70 2E ^^ ^^
  19. I had to create my own test data (thanks for that) but naturally I don't know how it conforms with yours. TABLE: product TABLE: bookingItem +----+-------------+-----------+--------+ +----+-----------+---------------------+---------------------+----------+ | id | productName | category | status | | id | productid | startTime | endTime | quantity | +----+-------------+-----------+--------+ +----+-----------+---------------------+---------------------+----------+ | 1 | Room 1 | Guestroom | Active | | 1 | 1 | 2024-01-01 11:32:01 | 2024-01-02 11:32:59 | 1 | | 2 | Room 2 | Guestroom | Active | | 2 | 2 | 2024-02-01 11:34:08 | 2024-02-03 11:34:24 | 2 | | 3 | Room 3 | Guestroom | Active | | 3 | 3 | 2024-03-01 11:34:56 | 2024-03-04 11:35:08 | 3 | | 4 | Room 4 | Guestroom | NULL | | 4 | 2 | 2024-04-01 12:20:20 | 2024-04-07 12:20:41 | 6 | | 5 | Room 5 | Guestroom | NULL | | 5 | 3 | 2024-05-01 01:21:49 | 2024-05-05 12:21:58 | 4 | +----+-------------+-----------+--------+ | 6 | 5 | 2024-06-19 12:23:03 | 2024-06-29 12:23:28 | 10 | | 7 | 2 | 2024-06-01 13:02:51 | 2024-06-15 13:03:16 | 14 | +----+-----------+---------------------+---------------------+----------+ On running your code with my data I get these results for Q1 and Q2. I have written the correct totals in red. As you can see there is a distinct pattern - your totals are the correct totals squared. However, I could not spot any multiplication in the code (I ran as separate query to confirm the correct totals) I have to say, in your code you really make a meal of those dates in the years and quarters considering that SQL can handle it easily. Here's my version... <?php ############################################### # CREATE YOUR OWN PDO DATABASE CONNECTION # # # require 'db_inc.php'; $pdo = mdbConnect('db1'); # # # # ############################################### $range = [ '2020-01-01', '2024-07-31' ]; $selectedYear = $_GET['year'] ?? 0; $whereYear = ''; if ($selectedYear) { $whereYear = 'AND YEAR(d.dt) = ?'; $range[] = $selectedYear; } $res = $pdo->prepare("WITH RECURSIVE dates(dt) AS ( SELECT ? UNION ALL SELECT dt + INTERVAL 1 MONTH FROM dates WHERE dt < ? ) SELECT YEAR(d.dt) AS yr , QUARTER(d.dt) as qtr , MONTHNAME(dt) AS mth , productName AS room , COALESCE(SUM(DATEDIFF(endTime, startTime)), '-') AS nights FROM product p CROSS JOIN dates d LEFT JOIN bookingitem b ON b.productid = p.id AND YEAR(d.dt) = YEAR(b.startTime) AND MONTH(d.dt) = MONTH(b.startTime) WHERE p.`status` = 'Active' $whereYear GROUP BY yr, qtr, MONTH(d.dt), p.id "); $res->execute($range); $results = $res->fetchAll(); $rooms = array_unique(array_column($results, 'room')); $theads = "<tr><th>Quarter</th><th>Month</th><th>" . join('</th><th>', $rooms) . "</th><th>Total</th></tr>\n"; ### RESTRUCTURE THE RESULTS ARRAY foreach ($results as $r) { $data[$r['yr']][$r['qtr']][$r['mth']][$r['room']] = $r['nights']; } ?> <!DOCTYPE html> <html lang='en'> <head> <meta charset="utf-8"> <title>Example</title> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <style type='text/css'> table { width: 100%; border-collapse: collapse; } th { background-color: #808080; color: white; padding: 8px; } td { padding: 4px 12px; text-align: right; } .ca { text-align: center; background-color: #EEE; } .la { text-align: left; background-color: #EEE; color: black; } </style> </head> <body> <header class='w3-indigo w3-padding w3-margin-bottom'> <h1>Guestroom Occupancy</h1> </header> <div class='w3-content w3-padding'> <?php ## OUTPUTFROM RESTRUCTURED ARRAY foreach ($data as $yr => $ydata) { echo "<h3>$yr</h3>\n <table border='1'> $theads "; foreach ($ydata as $qtr => $qdata) { $span = 3 + count($rooms); echo "<tr><th class='la' colspan='$span'>Quarter {$qtr}</th></tr>\n"; foreach ($qdata as $mth => $mdata) { echo "<tr><td>&nbsp;</td><td>$mth</td><td>" . join('</td><td>', $mdata) . "</td><td><b>" . array_sum($mdata) . "</b></td></tr>\n"; } } echo "</table>\n"; } ?> </div> </body> </html> Output
  20. It would also help immensely if you posted the actual code that gives your claimed results. The code you posted wil not even execute as it contains : SQL syntax error undefined variable values an infinite loop
  21. Why would you need to? If you want to output it to an html page showing the line breaks, use nl2br() EG echo nl2br( $row['TextField'] );
  22. Your first query is redundant - you are joining product and booking_items in the second query. You appear to have ignored @mac_gyver'scomments completely from your previous post. Still no test data so we can't see for ourselves what is happening. Are you saying the purpose of the two queries and all the php code is just to see how many days in each month?
  23. The assignment operator is "=", not "==". Instead of the for() loop, why not just use in_array() as I did? function GetColour($Balls,$Ball) { return in_array($Ball, $Balls) ? "#0000ff" : "#c53ba1"; }
  24. Alternative approach... <?php $winners = [ 'norm' => [1,23,27,36,48], 'stars' => [8,12] ]; $myNums = [ 'norm' => [1,3,27,38,48], 'stars' => [7,12] ]; $normCorrect = count(array_intersect($winners['norm'], $myNums['norm'])); $starsCorrect = count(array_intersect($winners['stars'], $myNums['stars'])); $results = sprintf ("\n%-15s%3d\n%-15s%3d", 'Normal', $normCorrect, 'Lucky Stars', $starsCorrect); $balls = ''; foreach ($myNums['norm'] as $b) { $bno = str_pad($b, 2, '0', STR_PAD_LEFT); $cls = (in_array($b, $winners['norm'])) ? 'match' : 'nomatch'; $balls .= "<div class='ball $cls'>$bno</div>"; } $balls .= '<br>'; foreach ($myNums['stars'] as $b) { $bno = str_pad($b, 2, '0', STR_PAD_LEFT); $cls = (in_array($b, $winners['stars'])) ? 'matchstar' : 'nomatchstar'; $balls .= "<div class='ball $cls'>$bno</div>"; } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Example</title> <meta charset="utf-8"> <style type='text/css'> body { font-family: verdana, arial, sans-serif; font-size: 12pt; } .ball { width: 40px; height: 40px; clip-path: circle(40%); text-align: center; display: inline-block; padding-top: 18px; margin: 5px; } .nomatch { background-color: #000000; color: #FFFFFF; } .nomatchstar { background-color: #808080; color: #FFFFFF; } .match { background-color: #006EFC; color: #FFFFFF; } .matchstar { background-color: #EEEE18; color: #000000; } </style> </head> <body> <div> <h3>Results</h3> <pre> <?= $results ?> </pre> <?= $balls ?> </div> </body> </html>
×
×
  • 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.