-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
On second examination, while the floating point limitations are something to consider, I think the issue here is simpler. usort expects the function to return an integer. As a result the small difference is simply being rounded to 0, and 0 means the two entries are considered equal. The reason your re-write works is because you're using 1 / -1 (but not accounting for 0/equal which is something to be fixed) and mine works because it uses the spaceship operator which returns an appropriate integer value.
-
This is not a bug, but a limitation on how floating point numbers get represented in binary. Some number cannot be perfectly represented so you end up with a close but not exact approximation. As you do math with these close but not perfect numbers, the error can accumulate enough to cause issues. The classic example is adding 0.1 and 0.2. echo (0.1+0.2 === 0.3)?'Matching':'Not a match'; If you run that, you'll get the Not a match message despite your expectations. This is due to the error accumulation of the math. You can see the real result if you serialze the equation. echo serialize(0.1+0.2); The result of that equation is actually 0.30000000000000004. In your case, the two arrays in question should be 0.01 difference, but the math ends up giving a difference of 0.00999999999999936 instead. I think the clearest way to solve the issue here is to add the two price/postage keys then round them to a precision of 2 and then compare them. Solves the precision issue and reads easier. usort($data, function($a, $b) { $aTotal=round($a['price']+$a['postage'],2); $bTotal=round($b['price']+$b['postage'],2); return $aTotal <=> $bTotal; });
-
Probably not enough data on the socket to be read. The read will block until it has read the number of bytes specified, or found a \n or \r line ending. Try making it non-blocking and see if it works.
-
mysql select statement is not taking space in consideration
kicken replied to Ivan007's topic in MySQL Help
Think about how that will get rendered after the PHP code is processed. You'll have: <input class="form-control" type="text" value=Information and Technology disabled readonly> You've set the value to just Information. The words and and Technology become unknown attributes. You need to put quotes around the value attribute content if you want to be able to use spaces. -
Setting "date.default_latitude" and similar settings
kicken replied to RonRN18's topic in PHP Installation and Configuration
The settings are used as defaults for the date_sunrise and date_sunset functions. The functions, and their related configuration directives are slated for removal. -
Try using google's search console to look for issues.
-
JSON Api results, loop through array and extract records to html table
kicken replied to gyesdahl's topic in Javascript Help
$objects['data'] contains your list of offers, so you loop over that and in each iteration you would produce one of your table outputs. foreach ($objects['data'] as $offer){ $html = buildOfferTable($offer); } Within each offer, you have your different itineraries. I'm presuming there will be one itinerary if it is oneWay: true, two otherwise. I'm also presuming the first itinerary is the trip there, second is return trip. If you just want to do a single set of rows like in your picture for both trips, then loop over the itineraries array and then the segments array. foreach ($offer['itineraries'] as $itin){ foreach ($itin['segments'] as $seg){ $row = createSegmentRow($seg); } } With $seg, you can start extracting the details, for example: $departCode=$seg['departure']['iataCode']; $arriveCode=$seg['arrival']['iataCode']; $carrierCode=$seg['carrierCode']; $number=$seg['number']; //... -
input Direction confusion in snake game javascript
kicken replied to polaryeti's topic in Javascript Help
inputDir holds the direction of movement in the x and y direction based on the key you pressed. -1 = move left or move up 0 = no movement in that direction 1 = move right or move down. In the rest of the code you would apply that movement with code like this: snakeArr.forEach((e,idx)=>{ e.x+=inputDir.x; e.y+=inputDir.y; }); -
Generally, no. What you need to do is figure out what criteria you can use to specify the row you want updated and then use that in your where condition to specify that row. Let's go back to just your CSV files. You start with this: name,class,index_number,term,subject1,subject1_test_score,subject1_exam_score,year acho c jubilee,js1,4,first term,maths,24,66,2022 eke g linda,js1,5,first term,maths,24,66,2022 anacho prince,js1,7,first term,maths,24,66,2022 So you load that into your DB and have your three rows with that data. Now you copy that csv and change the copy to: name,class,index_number,term,subject1,subject1_test_score,subject1_exam_score,year eke g linda,js1,5,first term,maths,50,100,2022 anacho prince,js1,7,first term,maths,50,100,2022 acho c jubilee,js1,4,first term,maths,50,100,2022 Open the two CVS's side-by-side then and look at them. Look at the first row of your new CSV file. How can you find the matching row in the original CSV file? Which fields do you need to compare to narrow the list down to a single row? Right now, you're looking at the class (js1), term (first term), and year (2022) columns. That doesn't eliminate anything though, all the rows in your original CSV file have those same values. You need something else. Once you've identified which criteria you can use to match the rows 1-to-1, you use that same criteria in your update statement's where clause so it can update that row.
-
No where clause will update the entire table. Every row. The issue is that the where clause you specified is not specific enough to identify a single row of the table. If you change your update to a select * with the same where clause you'll see that you get multiple rows in the result. All those rows will get updated by your update query. You need to add more or different conditions that will limit the update to a specific row (such as by using the id column for example).
-
No, you do not merge the else into the previous set of if statements. You replace the second set of if statements with only what was in the else branch. Like this. function next_day_delivery() { if( WC()->cart->is_empty() ) return; // Exit $cart_subtotal = WC()->cart->subtotal; $limit_free = 150; // Starting freee shipping amount $free_shipping = ''; // Initialising if ( $cart_subtotal < $limit_free ) { $free_shipping = sprintf( __('%s Add %s worth of goods to your order to get %s', 'woocommerce' ), '', // ' <img src="' . get_stylesheet_directory_uri() . '/images/shipping-icon.png"> ', strip_tags( wc_price( round( $limit_free - $cart_subtotal, 2 ) ) ), '<strong>' . __( 'FREE SHIPPING!', 'woocommerce' ) . '</strong>' ); } elseif ( $cart_subtotal >= $limit_free ) { $free_shipping = '<strong>' . __( ' You get FREE SHIPPING!', 'woocommerce' ) . '</strong>'; } $message = __( '', 'woocommerce' ) . $free_shipping; wc_print_notice( $message, 'success' ); }
-
Yes. That code will work to call the DeleteRow function when you click the button.
-
That is why I was asking about if you looked at the example. Doing it the way I showed does not require adding new event handlers to each row. You add your event handlers to the parent element which doesn't change and then used the passed in event details manipulate the row. The function name alone does not call the function, you need to follow it with (). ele3.addEventListener('click', function() { DeleteRow(); }) If you're not going to pass parameters, then you can skip the intermediate function and pass in a reference to your DeleteRow function directly, which you do by using just the name and no (). ele3.addEventListener('click', DeleteRow)
-
xampp php session files and firefox browser
kicken replied to jodunno's topic in PHP Installation and Configuration
Generally speaking, a person does not want to conditionally start a session. Either you're using the session data in your (so you start it), or you're not (so you don't). In addition, people don't generally care about empty session files (they get generated all the time usually). You're essentially trying to solve a problem that most people simply don't see a problem at all. Those empty files don't hurt anything and will get cleaned up eventually. On a side note, while what you are describing might make it slightly more difficult for your average person to download your images, it by no means prevents it. If the browser can display it, the user can save it, simple as that. -
Not entirely sure what you mean. If you're using addEventListener then whatever function you give it will be given a single event parameter. If you need others, then you use an intermediate function (usually a closure/inline function). node.addEventListener('click', function(){ yourOtherFunction(andParameter); }); Out of curiosity, did you look at the example I linked in my first post? Is there any particular reason you seem to be avoiding that method? Splitting your single table up in to three separate tables isn't really a great solution. If it's because I used divs rather than tables, then here is a table version of it.
-
cloneNode is the underlying DOM function. You're using jQuery so you need to use the jQuery equivalent which is clone.
-
Rather than try and change the button, just add a second button for delete row and control which one is for the row visible with CSS. That can possible be done easily by taking advantage of the :last-child pseudo selector. For example: <div id="input-grid"> <div class="row"> <div> <button type="button" name="add-row"> + </button> <button type="button" name="delete-row"> - </button> </div> ... </div> </div> With CSS: .row button[name=add-row], .row:last-child button[name=delete-row] { display: none; } .row:last-child button[name=add-row]{ display: inline; } The CSS sets the first sets add-row button to not be displayed for all rows, and the delete-row button to not be displayed in the last row. The next rule overrides the first to make the add-row button visible in the last row. With that, you don't need to futz around with maintaining your buttons in your JS code, just add or remove rows as needed and the correct button will show automatically.
-
Try browsing directly to your .env file on your website, for example http://example.com/.env and see if the file contents comes up. If it does, then that's your problem. Ideally you'd store your .env file outside of your webroot so it's inaccessible via any URL. If you're hosting provider does not allow for that, then you need to configure the webserver to not allow access to your .env file via .htaccess or some similar mechanism. If you can't do that, then the next best option is to store the credentials as PHP code in a .php file so even if someone does try and load the URL they won't see the PHP code.
-
If all you want to have is a small text-only tooltip, you can do that just by using the title attribute. <a href="#" title="The tooltip here">Link text</a>
-
The code you've posted here does not contain any error that would cause your described problem. However, I took a guess at your website URL and looked at the actual page and can say that the code you posted here is not the same as what is on the actual page. There is a difference in your <input> tags. If you look at them and identify what's missing you'll solve your issue. If you're still having trouble, make sure you post the actual code you are running on the site next time, and as text using a code block (the <> icon here) rather than as screenshots.
-
try not working - even the ones I copy as is from forums
kicken replied to jasonc310771's topic in PHP Coding Help
What error are you getting? -
Trying to get the cookie session functioning: "lost upon reopened browser".
kicken replied to oz11's topic in PHP Coding Help
You cannot set a cookie after you've already sent output. Cookies are part of the headers (ie, setcookie just turns into header('Set-cookie: ...')) so they must come before any other script output. That's what those errors are telling you. You have output starting in colourmodes.php on line 32 which is preventing your cookie from being set. You need to re-structure your application so you can set your cookies before anything else happens that would cause output to be sent. -
PHPunit testing instance of same object under different states.
kicken replied to NotionCommotion's topic in PHP Coding Help
I don't know much about PHPUnit or unit testing in general (only recently started trying to do it) but the documentation for PHPUnit's data providers has this note: To me, it sounds like that means your data provider will be fully iterated before the unit test is run, which would match the behavior you seem to be having. It's my understanding of unit tests that you generally should avoid having some state / external dependency. You should instead create mock objects as necessary to return the data you want.