Jump to content

Barand

Moderators
  • Posts

    24,604
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. Before you get to your header() you have already sent about 20 lines of HTML to the browser. Headers have to be sent before any other output. You should rearrange your code so that php code comes at the top and html at the end, as far as possible. That way any redirects are done before any output is sent.
  2. Anything that is in a php file, but outside the <?php .. ?> will be sent to the browser. Sending anything to the browser will cause (default) headers to be sent. An empty line before the opening <?php will cause this. An included php file that ends with ?> \n will send output. (For that reason never put ?> at end of included files). Thus it doesn't have to be an explicit header() call in your code. Also, when you call a header() like you have done, always "exit" after the call. If you don't the remainder of the page will still be executed.
  3. At the moment, then, they select an option but you don't store it with any data anywhere?
  4. I can't see a specific problem with your code, but it's not how I would write it $ono = 123; $filename = 'mytest.csv'; $res = $pdo->prepare("SELECT * FROM production_data WHERE insert_time < NOW() + INTERVAL 60 MINUTE AND order_id = ? "); $res->execute([$ono]); header('Content-type: application/csv'); header("Content-Disposition: attachment; filename=$filename"); $fp = fopen('php://output', 'w'); foreach ($res as $row) { fputcsv($fp, $row); } fclose($fp);
  5. thus... +----------------+ +-------------+ | mydata | | option | +----------------+ +-------------+ | user_id | +------| option_id | | option_id |>-------+ | option_name | | date_saved | +-------------+ +----------------+ SELECT d.option_id , o.option_name , count(*) as tot FROM mydata d JOIN option o USING (option_id) WHERE user_id = ? AND date_saved > CURDATE() - INTERVAL 12 MONTH GROUP BY d.option_id ORDER BY tot DESC EDIT: On second thoughts, make that FROM option LEFT JOIN mydata
  6. Then just count their usage over the last N months.
  7. How is your date stored in ppb_listings? Just to be sure, if it is 7pm now, you want all records with a start time before 8pm today, correct?
  8. You do that with a JOIN SELECT b.customer_name , j.tour_name FROM bookings b JOIN jobs j ON b.tour_id = j.id
  9. "Tour_name" should not be in the booking table, just the id
  10. The you didn't do it right. Post current code
  11. You need while (list($id, $name) = mysqli_fetch_row($result)) {
  12. They will see the name of the job they are booking in the dropdown, just as they do now. The only difference is what gets stored.
  13. You're making it difficult for yourself. The tour/job name should not be in the booking table. The only place that should occur in your database is in the tour/job table. It is just the tour id that be in the booking table. +------------------+ | booking | +----------------+ +------------------+ | tour/job | | booking_id | +----------------+ | tour_id |>----------------| tour_id | | cust_name | | tour_name | | cust_address | +----------------+ | order_at | | ... | | etc | +------------------+ When you create your dropdown options, the values of the options should be the id and not the name. Then all you do is insert $_POST['tour_name'] (which will actually be the id) into the booking data. Job done.
  14. This is the code I ran (of course using my similar table instead of yours) $sq2 = "SELECT pg_code FROM first_list WHERE st_ic = ?"; $stm = $conn->prepare($sq2); $stm->bind_param('s', $logged); $stm->execute (); $return2= $stm->get_result(); $r2 = $return2->fetch_all(); echo '<pre>' . print_r($r2, 1) . '</pre>'; foreach($r2 as $course){ foreach($course as $courses){ echo $courses.'<br>'; } } and this was the output Array ( [0] => Array ( [0] => DMM ) [1] => Array ( [0] => DKC ) [2] => Array ( [0] => DCS ) [3] => Array ( [0] => DPS ) ) DMM DKC DCS DPS FYI, here is a PDO version to give the same list $stm = $pdo->prepare("SELECT pg_code FROM first_list WHERE st_ic = ?"); $stm->execute([$logged]); foreach ($stm as $course) echo $course['pg_code'] . '<br>';
  15. Your code worked fine for me. Are you sure that, when you ran it, your logged user has more than 1 course?
  16. Use code tags ( <> button in toolbar ) when posting code.
  17. Unfortunately, this isn't a reliable guide. I usually browse the Activity page and select a topic. If I feel that the topic is not in my area of expertise, I will click the "Back" button and return to the Activity list. However, this still shows me as viewing the topic, which may be for a while if there are no other new topics. It isn't until I click "Home" that it again shows me as viewing the index.
  18. Do not use SELECT * Specify what you want and your (PDO) code becomes $query = "SELECT id , name as title , dep_date as start , ret_date as end FROM tours ORDER BY id"; $result = $con->query($query); echo json_encode($result->fetchAll());
  19. It looks like you are not returning valid JSON in your ajax response. If you are retrieving multiple rows then you need to send back an encoded array of rows (the whole result set) and then process it as such. You are encoding each row thus returning a list of several json encode array strings
  20. Very good!. In which case var_dump() would give string(5) "foot%" But if, say, an extra character (maybe a space) had crept in there, it would show something like string(6) "foot %" Your mission, should you choose to accept it, it to determine if $param_term really contains what you think it should contain. It's part of a process called "debugging".
  21. What if no new value has been posted but your session value already contains 50? Perhaps... $get_ppp = $_POST['ppp'] ?? $_SESSION['ppp'] ?? 15; $_SESSION['ppp'] = $get_ppp;
  22. Does this improve things? $get_data->bindParam(':param', $param_term, PDO::PARAM_STR); EDIT: nm - that's the default anyway. Does var_dump($param_term) give the expected resul?
  23. This is the code for the first <?php require '../db_inc.php'; $db = myConnect('josen'); $res = $db->query("SELECT concat(m.first_name, ' ', m.last_name) as name , m.email , m.phone , c.value as phone2 , t.region_id , GROUP_CONCAT(DISTINCT t.postcode ORDER BY region_id, postcode SEPARATOR ', ' ) as postcodes FROM hfwji_swpm_members_tbl m JOIN hfwji_members_towns mt USING (member_id) JOIN hfwji_towns t ON t.id = mt.town_id LEFT JOIN hfwji_swpm_form_builder_custom c ON m.member_id = c.user_id AND c.field_id = 33 GROUP BY region_id, m.member_id ORDER BY region_id, m.last_name; "); // // PROCESS THE QUERY RESULTS // $prev_id = ''; $prev_name = ''; $output = ''; $prev = ''; foreach ($res as $r) { if ($r['region_id'] != $prev) { if ($prev != '') { $output .= "</div></div>\n"; } $prev = $r['region_id']; $output .= <<<HEAD <div class='w3-container w3-padding w3-margin w3-border'> <div class="w3-panel w3-blue-gray"> <h3>Region {$r['region_id']}</h3> </div> <div class="w3-row"> HEAD; } $output .= <<<MEMBER <div class="w3-col m4"> <div class="w3-card-4 w3-light-gray w3-margin w3-padding member"> <i class="fas fa-user"></i><b>{$r['name']}</b><br> <i class="fas fa-envelope"></i>{$r['email']}<br> <i class="fas fa-phone"></i>{$r['phone']}&emsp;{$r['phone2']} <div class="w3-panel w3-padding w3-blue pcodes"> {$r['postcodes']} </div> </div> </div>\n MEMBER; } $output .= "</div>\n"; ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="generator" content="PhpED 19.5 (Build 19515, 64bit)"> <title>Example</title> <meta name="author" content="Barand"> <meta name="creation-date" content="07/12/2021"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.1/css/all.css"> <style type='text/css'> .member { line-height: 20px; } i { color: #2DABE1; margin-right: 16px; } .pcodes { font-size: 12pt; font-weight: 600; } </style> </head> <body> <?=$output?> </body> </html>
  24. That wasn't the issue. The postcodes in my data all have have only one region. The point is that Peter has several postcodes but not all in the same region.
  25. Yes. How you do it depends on how you want to handle those members who cover postcodes in more than one region (if there are any) Like this or show Peter like this
×
×
  • 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.