-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Or you could use jquery toggle to do the heavy lifting for you <div style='border: 2px solid black; padding: 16px; margin-bottom: 16px;' id='target'> Hello </div> <button onclick='showhide("target")'>Show/Hide</button> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> function showhide(id) { $("#"+id).toggle(0) } </script>
-
Inside the function, check it's display status. If hidden, show it. If not hidden, hide it.
-
Such as by passing the id of the div to be shown/hidden as a function argument? function hideDiv(divid) { document.getElementById(divid).style.display = "none"; } . . . <button onclick="hideDiv('welcomeDiv')" class="loginBut" style="font-family: 'Handjet', cursive; font-size: 2EM;">Close</button>
-
It won't let you reuse placeholder names** so you need :StartDate1 and :StartDate2 then provide the same value for both when you execute. $stmt->execute(['StartDate1' => $StartDate, 'Startdate2' => $StartDate]); Alternatively you can use ? placeholders $sqlAllData = "SELECT * FROM Bank_Data WHERE EntryDate > ? AND EntryDate <= DATE_ADD(?, INTERVAL 6 WEEK) ORDER BY EntryDate ASC, Output"; ... $stmt->execute( [ $StartDate, $StartDate ] ); ** it will if if you use emulated prepares, but that is a bad idea.
-
Try $expected = array( '1111', '2222', '2222', '3333' ); $received = array( '1111', '2222', '3333', '3333' ); $cExp = array_count_values($expected); $cRec = array_count_values($received); foreach (array_keys($cExp+$cRec) as $prod) { $e = $cExp[$prod] ?? 0; $r = $cRec[$prod] ?? 0; switch ($e <=>$r) { case -1: $check = 'Over'; break; case 0: $check = 'OK'; break; case 1: $check = 'Under'; break; } echo $prod . " Ordered: $e Received: $r - $check <br>"; } giving 1111 Ordered: 1 Received: 1 - OK 2222 Ordered: 2 Received: 1 - Under 3333 Ordered: 1 Received: 2 - Over
-
It isn't just the start of the page that counts. All sections of php code (other than <?=" echo only) must begin with <?php. If they don't, and you use <?, then the following php code will be treated as text and output to the page - as in your screenshot.
-
@dodgeitorelse3 "<?=" is valid shorthand for "<?php echo"
-
Your screenshot shows symptoms of php not executing because of the above reason
-
I am using Windows with localhost, pdo and mysql (although mine is v5.7 as I keep failing trying to install v8 - gave up and also installed MariaDB 11 on PC)
-
The easiest way to use it is set error reporting option when you connect, plus a couple of other options. This will save you from have to test for errors after every PDO method call. const HOST = 'localhost'; const USERNAME = '????'; const PASSWORD = '????'; const DATABASE = '????'; function pdoConnect($dbname=DATABASE) { $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $db; } then, to connect... $pdo = pdoConnect();
-
Code that is commented out seldom does.
-
Have you tried my suggestion?
-
Probably because of the sequence of events. I suspect it is ... page loads <script> is run client/list is loaded Try moving the code from <script> to the ready() function after the load so that the elements are loaded before you create their event handlers..
-
Inserting multiple values for one user in new column
Barand replied to PNewCode's topic in PHP Coding Help
The correct way to do it is use a JOIN in a query when you need the reqid, not to duplicate values from one table into another. -
Your "( .. )" are in the wrong places.
- 7 replies
-
- php
- array_search
-
(and 1 more)
Tagged with:
-
I agree with Gizmola^. Using a multidimensional array ... $probs = [ 'QB' => [ 'RB' => [ 1 => 11.22, 2 => 3.91, 3 => 0.15 ], 'TE' => [ 1 => 5.17, 2 => 0.80, 3 => 0.00 ], 'QB' => [ 1 => 9.44, 2 => 0.00, 3 => 0.00 ], 'WR' => [ 1 => 10.46, 2 => 8.67, 3 => 4.53 ], 'K' => [ 1 => 3.81, 2 => 0.19, 3 => 0.00 ], 'D' => [ 1 => 2.85, 2 => 0.07, 3 => 0.00 ] ] // rinse and repeat with the other MVPs and FLEXs ]; $lineup = 'QB, WR, WR, RB, K'; $arr = array_map('trim', explode(',', $lineup)); $mvp = array_shift($arr); $counts = array_count_values($arr); $probability = 0; foreach ($counts as $p => $n) { $probability += $probs[$mvp][$p][$n]; } echo '<br>'.$probability; // 23.7
-
Student subject Positioning based on score using php and mysql database
Barand replied to sule's topic in PHP Coding Help
I won't know until I get some useable data (table dump) to test with. Then I will gladly post a picture of the solution. -
Student subject Positioning based on score using php and mysql database
Barand replied to sule's topic in PHP Coding Help
I'd love to help but my query is having difficulty reading that picture of your data. -
My earlier post, showing 5 night occupied, was wrong. If one arrives on the 1st and departs on the 5th then the room is occupied on only 4 nights (1st, 2nd, 3rd, 4th) so you would ... LEFT JOIN ON r.room_id = rb.room_id AND occupied BETWEEN arrival AND departure - INTERVAL 1 DAY
-
It has a potential effect on any process that uses that table. For example, a search for rooms already booked now becomes a simple search for a date between X and Y instead of looking for overlapping date ranges.
-
I'd opt for CREATE TABLE `room_booking` ( `room_booking_id` int(11) NOT NULL AUTO_INCREMENT, `room_id` int(11) DEFAULT NULL, `booking_id` int(11) DEFAULT NULL, `occupied` date DEFAULT NULL, PRIMARY KEY (`room_booking_id`), UNIQUE KEY `room_id_2` (`room_id`,`occupied`), KEY `booking_id` (`booking_id`) ) ENGINE=InnoDB so a booking for 1st to 5th would be stored as room_id | date_occupied ----------+--------------- 1 | 2023-11-01 1 | 2023-11-02 1 | 2023-11-03 1 | 2023-11-04 1 | 2023-11-05 then the unique constraint on (roomid, occupied) does work. More records but safer.
-
Not sure that constraint is very useful. If you have Room 1 - 1st - 5th then no one else can book the same room from 1st to 5th, however it would allow 2nd to 4th (or any other overlap) which would still be a double booking.
-
ORDER BY level IS NULL, level
-
Whe you join a table with M records to a table with N matching records you get M*N records returned. Therefore you are now totalling Nx more records than before. You need to ensure you join 1 row from 1 tablw with 1 matching record in the other. You can do this with subqueries to get the individal tables' totals. SELECT t1.customer_id , t2.total_sales , t3.amt_paid FROM customers t1 LEFT JOIN ( SELECT customer_id , SUM(total_price) as total_sales FROM tbl_sales GROUP BY customer_id ) t2 USING (customer_id) LEFT JOIN ( SELECT customer_id , SUM(amt_paid) as amt_paid FROM tbl_sales_total WHERE status = 0 GROUP BY customer_id ) t3 USING (customer_id) WHERE t1.customer_id = 489639 Also, you have a LEFT JOIN to tbl_sales_total t3. You therefore cannot use WHERE t3.status = 0. That condition needs to go into the join condition otherwise the query behaves as though it were an ordinary (INNER) JOIN