-
Posts
24,551 -
Joined
-
Last visited
-
Days Won
821
Community Answers
-
Barand's post in I just have a question about a database table. was marked as the answer
It won't let you INSERT a new record with the same primary key as an existing record. The only way you can overwrite them is if you UPDATE them (or INSERT with an ON DUPLICATE KEY UPDATE option)
-
Barand's post in PHP Form just errors every time - Can't figure out why! was marked as the answer
For $_POST['submit'] to exist there must be an input form element with the name 'submit'.
A better way to check is
if ($_SERVER['REQUEST_METHOD'] == 'POST') { // data was posted - process it }
-
Barand's post in Sum and join 2 tables was marked as the answer
Your query joins each record from 'a' to many records from 'b' thus multiplying your totals.
Try
SELECT a.prod_id, a.prod_name , a.qty_received , b.qty_bot , a.qty_received - b.qty_bot as qty_remain FROM ( SELECT prod_id , prod_name , sum(prod_qty) as qty_received FROM tbl_distribution WHERE staff_id = 2962 GROUP BY prod_id ) a LEFT JOIN ( SELECT prod_id , sum(qty_bought) as qty_bot FROM tbl_sales_bar WHERE staff_id = 2962 GROUP BY prod_id ) b USING (prod_id);
Your tables are in dire need of normalization. For example, "prod_name" should occur once in your database (in a product table) and not be repeated in several tables.
PS
In future, don't post pictures of your data, post the data. It was not a great deal of fun building the test tables from those images so that I could test your query.
-
Barand's post in Find no.of position in column was marked as the answer
What do get if you run the subquery on its own?
SELECT GROUP_CONCAT(DISTINCT Average ORDER BY Average DESC ) FROM mark; I suspect that your "average" column is varchar instead of a numeric type. (in my table it's DECIMAL(8,2) so that it sorts correctly.
-
Barand's post in Can't find error in php mysql jquery was marked as the answer
Use your browser's developer tools network tab to check what is being sent and received by the ajax request
-
Barand's post in Matrix combination was marked as the answer
Does this look right?
A1 A2 A3 A4 A5 A1 B2 A3 A4 A5 A1 C2 A3 A4 A5 B1 A2 A3 A4 A5 B1 B2 A3 A4 A5 B1 C2 A3 A4 A5 C1 A2 A3 A4 A5 C1 B2 A3 A4 A5 C1 C2 A3 A4 A5 A1 A2 A3 A4 B5 A1 B2 A3 A4 B5 A1 C2 A3 A4 B5 B1 A2 A3 A4 B5 B1 B2 A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2 C3 C4 A5 B1 A2 C3 C4 A5 B1 B2 C3 C4 A5 B1 C2 C3 C4 A5 C1 A2 C3 C4 A5 C1 B2 C3 C4 A5 C1 C2 C3 C4 A5 A1 A2 C3 C4 B5 A1 B2 C3 C4 B5 A1 C2 C3 C4 B5 B1 A2 C3 C4 B5 B1 B2 C3 C4 B5 B1 C2 C3 C4 B5 C1 A2 C3 C4 B5 C1 B2 C3 C4 B5 C1 C2 C3 C4 B5 A1 A2 C3 C4 C5 A1 B2 C3 C4 C5 A1 C2 C3 C4 C5 B1 A2 C3 C4 C5 B1 B2 C3 C4 C5 B1 C2 C3 C4 C5 C1 A2 C3 C4 C5 C1 B2 C3 C4 C5 C1 C2 C3 C4 C5
-
Barand's post in PHP script to export for Facebook data feed CSV was marked as the answer
These are the differences I can see
Your "after" file has a comma at the end of line 1, the "before" one doesn't.
Your "after" file has a newline character at the end of the final line (extra blank line at end of file); "before" doesn't.
"After" prices not rounded to 2 dec; "before" ones are. (123.50 becomes 123.5 etc)
-
Barand's post in error_reporting: hide the warnings was marked as the answer
The point is that that your code to set the error reporting level is not being executed.
When you run a PHP script is is first parsed for errors (startup errors). If none are found the script is then executed (and your error reporting code will be executed) but, as in this case, if errors are found your code is not executed.
This was pointed out to you by requinix earlier...
-
Barand's post in What does the x and y value mean here? Can you show in a figure? was marked as the answer
The closest x or y can be to the edge is the radius of the ball. When either of them reach that position, change direction.
-
Barand's post in Insert into .. select was marked as the answer
That will only select one record (g1/s1 or g1/s2) so you will only insert one new record
-
Barand's post in school database was marked as the answer
The SQL tutorial link in my signature may help to get you started.
-
Barand's post in Converting time from format in database was marked as the answer
You can do it in your query with
SELECT date_format(created_at, '%b %e %Y %h:%i%p'), ... or you can do it in php with
date('M j Y g:ia', strtotime($row['created_at']))
-
Barand's post in round to 1 decimal was marked as the answer
There are a couple of solutions that you can apply on the MySql side.
1 ) Use mysql's ROUND() function i your query
mysql> create temporary table test1 (amount float); mysql> insert into test1 (amount) Values (PI()); mysql> select amount, round(amount, 1) as rounded from test1; +---------+---------+ | amount | rounded | +---------+---------+ | 3.14159 | 3.1 | +---------+---------+ 1 row in set (0.03 sec) 2 ) Define the column as DECIMAL instead of FLOAT
mysql> create temporary table test2 (amount DECIMAL(8,1)); mysql> insert into test2 (amount) Values (PI()); mysql> select amount from test2; +--------+ | amount | +--------+ | 3.1 | +--------+ 1 row in set (0.00 sec)
-
Barand's post in JSON Api results, loop through array and extract records to html table was marked as the answer
It's been a particularly miserable , grey, rainy sort of a day so I passed some time on this
<?php $json = '{"meta":{"count":5,"links":{"self":"https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=CPT&destinationLocationCode=LGW&departureDate=2023-03-01&returnDate=2023-03-08&adults=1&travelClass=ECONOMY¤cyCode=ZAR&max=5"}},"data":[{"type":"flight-offer","id":"1","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT18H50M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"5","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T01:15:00"},"arrival":{"iataCode":"LGW","terminal":"S","at":"2023-03-02T05:45:00"},"carrierCode":"QR","number":"5943","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT7H30M","id":"6","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"5","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"6","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"2","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT19H15M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T19:10:00"},"arrival":{"iataCode":"DOH","at":"2023-03-02T05:55:00"},"carrierCode":"QR","number":"1370","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"1","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"2","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"1","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"2","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"3","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT25H30M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"3","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"4","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"S","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:45:00"},"carrierCode":"QR","number":"5942","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT6H40M","id":"7","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"8","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12632.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12632.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12632.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"3","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"4","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"7","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"8","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"4","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":7,"itineraries":[{"duration":"PT18H50M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T12:55:00"},"arrival":{"iataCode":"DOH","at":"2023-03-01T23:40:00"},"carrierCode":"QR","number":"1372","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"5","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T01:15:00"},"arrival":{"iataCode":"LGW","terminal":"S","at":"2023-03-02T05:45:00"},"carrierCode":"QR","number":"5943","aircraft":{"code":"777"},"operating":{"carrierCode":"BA"},"duration":"PT7H30M","id":"6","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"N","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:50:00"},"carrierCode":"QR","number":"328","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT6H45M","id":"9","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"10","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12670.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12670.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12670.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"5","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"6","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"9","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"10","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]},{"type":"flight-offer","id":"5","source":"GDS","instantTicketingRequired":false,"nonHomogeneous":false,"oneWay":false,"lastTicketingDate":"2023-03-01","numberOfBookableSeats":9,"itineraries":[{"duration":"PT19H15M","segments":[{"departure":{"iataCode":"CPT","at":"2023-03-01T19:10:00"},"arrival":{"iataCode":"DOH","at":"2023-03-02T05:55:00"},"carrierCode":"QR","number":"1370","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT9H45M","id":"1","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-02T08:05:00"},"arrival":{"iataCode":"LGW","terminal":"N","at":"2023-03-02T12:25:00"},"carrierCode":"QR","number":"327","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT7H20M","id":"2","numberOfStops":0,"blacklistedInEU":false}]},{"duration":"PT19H10M","segments":[{"departure":{"iataCode":"LGW","terminal":"N","at":"2023-03-08T14:05:00"},"arrival":{"iataCode":"DOH","at":"2023-03-08T23:50:00"},"carrierCode":"QR","number":"328","aircraft":{"code":"788"},"operating":{"carrierCode":"QR"},"duration":"PT6H45M","id":"9","numberOfStops":0,"blacklistedInEU":false},{"departure":{"iataCode":"DOH","at":"2023-03-09T02:15:00"},"arrival":{"iataCode":"CPT","at":"2023-03-09T11:15:00"},"carrierCode":"QR","number":"1369","aircraft":{"code":"77W"},"operating":{"carrierCode":"QR"},"duration":"PT10H","id":"10","numberOfStops":0,"blacklistedInEU":false}]}],"price":{"currency":"ZAR","total":"12670.45","base":"6370.00","fees":[{"amount":"0.00","type":"SUPPLIER"},{"amount":"0.00","type":"TICKETING"}],"grandTotal":"12670.45"},"pricingOptions":{"fareType":["PUBLISHED"],"includedCheckedBagsOnly":true},"validatingAirlineCodes":["QR"],"travelerPricings":[{"travelerId":"1","fareOption":"STANDARD","travelerType":"ADULT","price":{"currency":"ZAR","total":"12670.45","base":"6370.00"},"fareDetailsBySegment":[{"segmentId":"1","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"2","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"9","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}},{"segmentId":"10","cabin":"ECONOMY","fareBasis":"NLR1R1RX","brandedFare":"ECLASSIC","class":"N","includedCheckedBags":{"quantity":2}}]}]}],"dictionaries":{"locations":{"CPT":{"cityCode":"CPT","countryCode":"ZA"},"DOH":{"cityCode":"DOH","countryCode":"QA"},"LGW":{"cityCode":"LON","countryCode":"GB"}},"aircraft":{"77W":"BOEING 777-300ER","777":"BOEING 777-200/300","788":"BOEING 787-8"},"currencies":{"ZAR":"S.AFRICAN RAND"},"carriers":{"QR":"QATAR AIRWAYS","BA":"BRITISH AIRWAYS"}}}'; $array = json_decode($json, true); $html = ''; foreach ($array['data'] as $offer) { $html .= buildOfferTable($offer); } function buildOfferTable($offer) { $html = "<div class='w3-row w3-padding w3-topbar'> <div class='w3-col w3-quarter'> Offer ID : {$offer['id']} </div> <div class='w3-col w3-quarter'> Source : {$offer['source']} </div> <div class='w3-col w3-half'> <b>Total Price : {$offer['price']['total']} {$offer['price']['currency']}</b> </div> </div> <table class='w3-table w3-bordered'> <tr class='w3-indigo'> <th>Segment</th> <th>Flight No</th> <th>Departure Time</th> <th>Arrival Time</th> </tr> "; foreach ($offer['itineraries']as $itins) { foreach ($itins['segments'] as $segment) { $html .= segmentRow($segment); } } $html .= "</table>\n<br>"; foreach ($offer['travelerPricings'] as $k => $tp) { $n = $k + 1; $html .= "Traveller $n : {$tp['travelerType']}<br> Amount : {$tp['price']['total']} {$tp['price']['currency']}<br><br> "; } return $html; } function segmentRow($segment) { $dt = (new DateTime($segment['departure']['at']))->format('Y-m-d H:i'); $at = (new DateTime($segment['arrival']['at']))->format('Y-m-d H:i'); $row = "<tr> <td>{$segment['departure']['iataCode']}-{$segment['arrival']['iataCode']}</td> <td>{$segment['carrierCode']} {$segment['number']}</td> <td>$dt</td> <td>$at</td> </tr> "; return $row; } ?> <!DOCTYPE=html> <html lang="en"> <head> <meta charset='utf-8'> <title>Flight Offers</title> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> </head> <body> <h1>Flight Offers</h1> <div class='w3-content'> <?= $html ?> </div> </body> </html> producing 5 offers like this ...
-
Barand's post in Php variable not accessible was marked as the answer
$data = '{"location":{"name":"London","region":"City of London, Greater London","country":"United Kingdom","lat":51.52,"lon":-0.11,"tz_id":"Europe/London","localtime_epoch":1672618641,"localtime":"2023-01-02 0:17"},"current":{"last_updated_epoch":1672618500,"last_updated":"2023-01-02 00:15","temp_c":8.0,"temp_f":46.4,"is_day":0,"condition":{"text":"Light rain","icon":"//cdn.weatherapi.com/weather/64x64/night/296.png","code":1183},"wind_mph":4.3,"wind_kph":6.8,"wind_degree":220,"wind_dir":"SW","pressure_mb":1009.0,"pressure_in":29.8,"precip_mm":0.0,"precip_in":0.0,"humidity":93,"cloud":25,"feelslike_c":7.0,"feelslike_f":44.7,"vis_km":10.0,"vis_miles":6.0,"uv":1.0,"gust_mph":5.8,"gust_kph":9.4}}'; $characters = json_decode($data, 1); // decode the JSON feed as array echo $characters['location']['name'] . '<br>'; echo $characters['current']['condition']['text'] . '<br>'; echo $characters['current']['condition']['code'] . '<br>'; If you want to stay with objects...
$data = '{"location":{"name":"London","region":"City of London, Greater London","country":"United Kingdom","lat":51.52,"lon":-0.11,"tz_id":"Europe/London","localtime_epoch":1672618641,"localtime":"2023-01-02 0:17"},"current":{"last_updated_epoch":1672618500,"last_updated":"2023-01-02 00:15","temp_c":8.0,"temp_f":46.4,"is_day":0,"condition":{"text":"Light rain","icon":"//cdn.weatherapi.com/weather/64x64/night/296.png","code":1183},"wind_mph":4.3,"wind_kph":6.8,"wind_degree":220,"wind_dir":"SW","pressure_mb":1009.0,"pressure_in":29.8,"precip_mm":0.0,"precip_in":0.0,"humidity":93,"cloud":25,"feelslike_c":7.0,"feelslike_f":44.7,"vis_km":10.0,"vis_miles":6.0,"uv":1.0,"gust_mph":5.8,"gust_kph":9.4}}'; $obj = json_decode($data); // decode the JSON feed as object echo $obj->location->name . '<br>'; echo $obj->current->condition->text . '<br>'; echo "<img src='{$obj->current->condition->icon}'>" . '<br>'; echo $obj->current->condition->code . '<br>';
-
Barand's post in Enable PHP code in HTML was marked as the answer
PHP code must be in a .php file to be executed (with a standard configuration) However a .php file does not need to contain any php code, it can be html only. So any html you can do in an .html file should work in a .php file.
Define the background image in your css - it should work the same in either.
-
Barand's post in Derive field name from accepted / known field name [dimensional or array fieldname] was marked as the answer
The id of an element must be unique, so change those id="name" to class="name"
data attributes are useful. Give each pair of fields the same data-id value. (Easier than parsing names)
For example
<!DOCTYPE=html> <html lang="en"> <head> <meta charset='utf-8'> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> $(function() { $(".weekday").click( function() { let id = $(this).data("id") // get data-id value of checkbox let time = $(".name[data-id="+id+"]") // find timing inut with same data-id value if ($(this).is(":checked")) { $(time).focus() } else { $(time).val("") } }) }) </script> </head> <body> <input name="weekday[8]" type="checkbox" value="21" class="weekday" checked data-id="8"> Monday <br> Timing <input name="timing[8]" type="text" class="name" value="11" size="45" data-id="8"> <br><br> <input name="weekday[9]" type="checkbox" value="99" class="weekday" data-id="9"> Tuesday <br> Timing <input name="timing[9]" type="text" class="name" value="" size="45" data-id="9"> <br><br> <input name="weekday[10]" type="checkbox" value="77" class="weekday" data-id="10"> Wednesday <br> Timing <input name="timing[10]" type="text" class="name" value="" size="45" data-id="10"> </body> </html>
-
Barand's post in add toolo tips to hyperlink was marked as the answer
You need to put it in quotes otherwise it accepts the value up to the first space only
<a href="StatementEntry.php?ID=<?=$ID?>" title="<?=$AddDate?>"> ^ ^
-
Barand's post in Like Dislike front end working but in database number is not increasing .... Pls help me was marked as the answer
Have you got php error reporting turned on?
Have you looked at your browser developer tools ( network tab ) to check that the ajax info is being passed OK?
Check that your queries are working correctly - put this code just before your mysqli_connect
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
-
Barand's post in Student class position generation was marked as the answer
Here's how I'd do it without the windowing functions
Note: if you have
A 98 B 98 C 95 the A and B a re ranked 1, C is ranked 3.
$grade_class = 'JS1'; $grade_name = 'EMMANUEL OKONJI'; $grade_term = 'First Term'; $grade_year = '2022'; $student_class_position = $conn->prepare( "SELECT rank FROM ( SELECT ord.grade_id , @seq := @seq+1 as seq , @rank := CASE WHEN ord.grand_total = @prev THEN @rank ELSE @seq END as rank , @prev := ord.grand_total as grand_total FROM ( SELECT grade_id , g.grand_total FROM student_grade g ORDER BY grand_total DESC LIMIT 18446744073709551615 ) ord JOIN (SELECT @seq:=0, @rank:=0,@prev:=0) init ) ranked JOIN student_grade g ON g.grade_id = ranked.grade_id WHERE class = ? AND name = ? AND term = ? AND year = ? "); $student_class_position->bind_param('ssss', $grade_class, $grade_name, $grade_term, $grade_year); $student_class_position->execute(); $student_class_position->bind_result($position); $student_class_position->fetch(); echo $position; I used a prepared statement so user data is not inserted into the query (SQL injection attack prevention)
-
Barand's post in Function in php was marked as the answer
OK - here's the "add" case...
case 'add': $result = 0; foreach ($exp['children'] as $child) { $result += evaluate($child); } break;
-
Barand's post in PHP PDO query within while loop only returns first row was marked as the answer
Slightly different approach then. Store the category query results in an array.
$stmt = $pdo->query("SELECT categoryID , categoryName FROM tbl_categories WHERE categoryActive = 1 ORDER BY categoryID "); $cat_options = []; /// store cat data in array foreach ($statement as $row) { $cat_options[$row['categoryID']] = $row['categoryName']; } // main loop here while ($row = $stmt->fetch()) { echo "<select name='categoryID' class='select200px' required> <option value=''>Select...</option>"; foreach ($cat_options as $id => $cat) { $sel = $row['categoryID'] == $id ? 'selected' : ''; echo "<option $sel value='$id'>$cat</option>"; } echo "</select>"; }
-
Barand's post in issue with a random number being inserted in the place of the right value in a query was marked as the answer
Looks like you are trying to store a 19 digit number in an INT field with a maximum value of 2147483647. Your voucher code is actually a string that consists of numeric characters (like a phone number) so store it as one, say VARCHAR(20);
-
Barand's post in get all keys that match value from multidimensional array was marked as the answer
Use array keys instead of array_search
$results = array_keys(array_column($data, 'oname'), 'Border.aao');
-
Barand's post in Warning: Undefined array key, the query mysql is working well, is a php problem was marked as the answer
The column names in the query results wil be
id_chocolate name_chocolate id_type_chocolate type_chocolate id_chocolate The tablename. prefixes are not part of them.