Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation since 12/29/2022 in Posts

  1. Create a "valid_ratings" table in your DB containg a row for each valid rating (1-5). Useful for creating dropdowns or radio button lists for the user to choose from. If you don't want to this, you can create it as a temporary table when you want thse totals # # Additional valid ratings table # $pdo->exec("create temporary table valid_rating (rating int unsigned not null primary key)"); $pdo->exec("insert into valid_rating values (1), (2), (3), (4), (5)"); # # get ratings totals # $res = $pdo->query("SELECT v.rating , count(r.id) as total FROM valid_rating v LEFT JOIN reviews r USING (rating) GROUP BY rating; "); printf("<pre>\n| Rating | Total |\n\n"); foreach ($res as $r) { printf("| %6d | %5d |\n", $r['rating'], $r['total']); } | Rating | Total | | 1 | 2 | | 2 | 2 | | 3 | 2 | | 4 | 0 | | 5 | 3 | An alternative solution is the one @gizmola alluded to $results = array_fill_keys(range(1,5), 0); // create array with 0 total for all possible ratings $res = $pdo->query("SELECT rating , count(*) as total FROM reviews GROUP BY rating "); foreach ($res as $r) { $results[$r['rating']] = $r['total']; // put totals from query into the array } printf("<pre>\n| Rating | Total |\n\n"); foreach ($results as $rating => $total) { printf("| %6d | %5d |\n", $rating, $total); }
    1 point
  2. 1 point
  3. if you do this - a majority of this code will go away. assuming i decoded what you are trying to produce as output. the following should be all the code that you need for the data table section - // pre-fetch the data, indexing/pivoting it using the station, then fuel as indexes $data = []; while ($row = sqlsrv_fetch_array($result)) { $data[$row['station']][$row['fuel']] = $row; } // produce the output ?> <table class = "main"> <tr class="main"><td></td> <?php // output the heading foreach($fuel as $fu) { echo "<td class = 'main'>$fu</td>"; } ?> <td class = "main">Atnaujinta</td></tr> <?php // output the data foreach($station as $st) { echo "<tr><td class='main'><a href='levelStation.php?station=$st'><b>$st</b></a></td>"; foreach($fuel as $fu) { if(empty($data[$st][$fu]['vol'])) { echo '<td>-</td>'; } else { $row = $data[$st][$fu]; $class = ''; if ($row['fmm']<=100) $class = 'class="low"'; if ($row['fmm']>100 AND $row['fmm']<250) $class = 'class="alert"'; if ($row['vmm']>=5) $class = 'class="water"'; $qs = []; $qs['station'] = $st; $qs['fuel'] = $fu; $qs['type'] = 'all'; $qs = http_build_query($qs); echo "<td $class><a href='levelFuel.php?$qs'>{$row['vol']}</a></td>"; } } echo "<td>".date_format(date_create($row['date']),"Y-m-d H:i:s")."</td></tr>\n"; } // output the totals ?> <tr><td>Iš viso:</td> <?php foreach($fuel as $fu) { $sum = 0; foreach($station as $st) { $sum += $data[$st][$fu]['vol']??0; } echo "<td class = 'main'>$sum</td>"; } ?> <td></td></tr> </table>
    1 point
  4. If you need a single array then you'll have to do away with the prices objects and re-bundle their data into arrays. array( 0 => array( "prd" => 2380, "id" => "173489", "price" => "65.00", "stores" => array( "store 1", "store 2" ) ) ) Unless your spreadsheet builder thing is a pain, you could take that 0 => array and re-key it to the prd as 2380 => array. Similar to before, you can then use the prd every time to insert-or-update into this larger array: insert when there is no existing [2380] yet, update with array[2380]["stores"][] = "store 2" when it does exist.
    1 point
  5. 1. You need an array to put all the data you're receiving. $newArray isn't the greatest name but it'll work for the moment. 2. For each price item you receive from the API, check if you have it in that array already: if so then update its list of stores, otherwise add it. It looks like $Data is: an array of prices, where each price is a "prices" object, and that object has a private "container" array of the data. The problem here is that you can't (nor, in fact, should) add anything to that container array: it pollutes the concept of the "prices" object with data it doesn't know about. In your shoes, I think I would change the above approach to be: you have two arrays, one of all the prices with no store data, and another that tells you which prices are in which store. The new approach is: 1. You need the one array for all the data - let's say "$allPrices". You need a second array just to associate prices with stores - let's say "$pricesToStores". 2. For each price item you receive from the API, add it to $allPrices. Because there will be duplicates, don't add it blindly but instead index the array by the unique identifier; that'll be either the "prd" or the "id", I can't tell. 3. At the same time, add information to $pricesToStores for the price item and the store. They should be indexed by the prd/id as well, and the array values can be the set of stores it was found in. There's probably a small issue though: when two stores have the same item, is the data for those two items exactly the same? I think not. My guess is that the "prd" will be the same but the "id" will not (or vice versa). If you simply keep one of the prices in $allPrices then you lose what the other ones were, so perhaps you might need to retain all the prices together in a sub-array. But if you have to do that, does the price data mention which store it came from already? Because if it does then the $pricesToStores array is pointless. So after all that, a question: what does the price data look like for 2+ stores that have the "same" one?
    1 point
  6. The way to do this in mysql is to store the address in a varbinary(16). This is because the IP address is a number, and the formatting is simply to make the IP scheme understandable. MySQL has specific functions for converting an ip address to and from this format, and handles the issue of whether the IP address is in v4 or v6 format. Use the v6 functions as they handle both v4 and v6 ip addresses. inet6-aton inet6-ntoa
    1 point
  7. the following is an example showing the code and queries needed to accomplish this task - <?php // initialization // these settings should be in the php.ini on your system - error_reporting(E_ALL); ini_set('display_errors', '1'); // Start the session session_start(); // fake a logged in user $_SESSION['user_id'] = 1; // insure the current visitor is logged in if(!isset($_SESSION['user_id'])) { // handle a non-logged in user here... header('location:index.php'); die; // stop code execution } // use exceptions for database statement errors and only handle the exception for user recoverable errors // based on the sql syntax error posted, you ARE using exceptions for database statement errors. do yourself a favor and remove all the existing database error handling logic since it is no longer being used and is just cluttering up your code. require 'pdo_connection.php'; $post = []; // array to hold a trimmed working copy of the form data $errors = []; // array to hold user/validation errors // post method form processing if($_SERVER['REQUEST_METHOD'] === 'POST') { // input(s) - gname, this should be the selected user's id - e.g. gid or similar // trim all the input data at once $post = array_map('trim',$_POST); // if any input is an array, use a recursive trim call-back function here instead of php's trim // validate the input data // the selected user's id if($post['gid'] === '') { $errors['gid'] = 'You must select a user'; } else if($post['gid'] == $_SESSION['user_id']) { $errors['gid'] = 'You cannot select yourself'; } else { // find if the selected user exists $sql = "SELECT COUNT(*) FROM users WHERE id=?"; $stmt=$pdo->prepare($sql); $stmt->execute([ $post['gid'] ]); if(!$stmt->fetchColumn()) { // if you see this error, it is either due to a programming mistake or someone submitting data values that are not from your code $errors['gid'] = 'The selected user does not exist'; } } // if no errors, use the data if(empty($errors)) { // since it is doubtful the OP will change what they are doing, the following updates the value in the token column // start transaction $pdo->beginTransaction(); // subtract 1 token from the current user, if they have enough tokens $sql = "UPDATE users SET token=token-1 WHERE token > 0 AND id=?"; $stmt=$pdo->prepare($sql); $stmt->execute([ $_SESSION['user_id'] ]); if($stmt->rowCount()) { // the UPDATE query affected the row, token was > 0 // add 1 token to the recipient user $sql = "UPDATE users SET token=token+1 WHERE id=?"; $stmt=$pdo->prepare($sql); $stmt->execute([ $post['gid'] ]); } else { // the UPDATE query didn't affect the row, token is not > 0 $errors['token'] = "You don't have enough tokens"; } // if you are here, no database errors/exceptions occurred, commit the transaction $pdo->commit(); } // if no errors, success if(empty($errors)) { $_SESSION['success_message'] = "You have successfully gifted a token"; die(header("Refresh:0")); } } // get method business logic - get/produce data needed to display the page $sql = "SELECT id, username FROM users ORDER BY username"; $stmt = $pdo->query($sql); $all_user_data = $stmt->fetchAll(); // html document starts here... ?> <?php // test for, display, and clear any success message if(!empty($_SESSION['success_message'])) { echo "<p>{$_SESSION['success_message']}</p>"; unset($_SESSION['success_message']); } ?> <?php // test for and display any errors if(!empty($errors)) { echo '<p>'.implode('<br>',$errors).'</p>'; } ?> <?php // display the form, repopulating form fields using any data in $post ?> <form method='post'> <select name='gid'> <option value=''>Select a user</option> <option value='234'>An invalid user</option> <?php foreach($all_user_data as $row) { $sel = isset($post['gid']) && $post['gid'] == $row['id'] ? 'selected' : ''; echo "<option value='{$row['id']}' $sel>{$row['username']}</option>"; } ?> </select><br> <input type='submit'> </form> this code renamed the session variable, because many things have 'id's, what exactly is the id stored in the session? uses the much simpler and more modern PDO database extension.
    1 point
  8. You were advised to use usort(). Your custom function would compare the totals of each pair of records ($a and $b) and return a negative value if $a should sort before $b or positive if $a sorts after $b. (ie total A - total B) $listings = $data['listings']; usort($listings, function($a, $b) { return $a['item_price']['value'] + $a['postage']['price']['value'] - $b['item_price']['value'] - $b['postage']['price']['value']; }); echo '<pre>' . print_r($listings, 1) . '</pre>';
    1 point
  9. try using a custom sort function # # Sort attendees on course, name # usort($attendees, function($a, $b) { $x = $a['course']<=>$b['course']; if ($x == 0) return $a['name']<=>$b['name']; return $x; }); # # Add sorted attendees to result array # $result = array(); foreach ($attendees as $attendee): $result[$attendee['course']][] = $attendee; endforeach; # # View result # echo '<pre>' . print_r($result, 1) . '</pre>'; P.S. You didn't say in what order you want them. If your aim is merely to get the courses in order then you could use ksort($result) (instead of your current sort() )to order the keys.
    1 point
  10. 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 ...
    1 point
  11. AND AGAIN - A 12 YEAR OLD SHOULD NOT BE OPENED.
    1 point
  12. there's nothing wrong with the POSTED code (just tested.) errors like this are usually caused by copy/pasting code that's been published on the web, with smart/curly quotes, which then produce php errors since those type of characters have no meaning in php, but which get converted back to straight quotes when code gets posted on a programming help forum, and therefor work when tried. delete and re-type the line of code.
    1 point
  13. you would have been getting php errors at the reference to the connection variable. php's error_reporting should always be set to E_ALL. when learning, developing, and debugging code/query(ies), display_errors should be set to ON. when on a live/public server, display_errors should be set to OFF, and log_errors should be set to ON.
    1 point
  14. what output are you getting on the web page? if it's a blank page, what does the 'view source' in your browser show? can you echo a string using php code? is your code doing any redirects that could discard any output from the web page if php's output_buffering is ON? do you have php's error_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your system, so that php will help you by reporting and displaying all the errors it detects? stop and start your web server to get any changes made to the php.ini to take effect and check that the settings actually got changed to those values by using a phpinfo(); statement in a .php script file. do you have error handling for all the database statements that can fail - connection, query, prepare, execute, and a few others? the simplest way of adding error handling, without adding conditional logic at each statement, is to use exceptions for errors and in most cases simply let php catch and handle the exception, where php will use its error related settings (see the previous paragraph above) to control what happens with the actual error information (database statement errors will 'automatically' get displayed/logged the same as php errors.) to enable exceptions for errors for the mysqli extension, add the following line of code before the point where you make the database connection - mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    1 point
  15. $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>';
    1 point
  16. As I told you before, you need to get the database right before you embark on the processes - you are not ready yet for complex queries. If you must run before you can crawl then there is an example of ranking queries in the SQL Tutorial link in my signature and also here in this forum.
    1 point
  17. Find an API for the CRM and write PHP code to use it. You haven't given enough information to be able to answer better than that...
    1 point
  18. sleep() , perchance to dream.
    0 points
This leaderboard is set to New York/GMT-05:00
×
×
  • 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.