-
Posts
24,565 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
For the benefit of those of us who can't read your mind, what were you expecting? In what way did it not work?
-
I'd use array_chunk, as you were planning to do.
-
Your file name is index.html and not index.php. You need a php file for php code to be executed.
-
Your array will look like this Each id in the array items points to the index of that items child array [edit]... To get you started foreach ($data[1] as $main) { echo $main['name'] . '<br>'; foreach ($data[$main['id']] as $mod) { echo "- {$mod['name']}<br>"; } }
-
Looking closer at your data, the function would not need to be recursive. A simple nested loop would do once you have the array as you don't have an indeterminate number of levels (just 2)
-
-
BULLSH*T. If you actually read @kicken's reply you will see he is using two different tables in his example.
-
Show categories with subcategories (parent, child)?
Barand replied to Guldstrand's topic in MySQL Help
Example here -
Just think how much quicker we coud have got you there if you'd said what you were really trying to! The answer to that question should have been "No, I want all those with a time after 6pm today"
-
GROUP BY not working properly when used with multiple joined tables
Barand replied to imgrooot's topic in PHP Coding Help
Answer: The bits you got wrong are... The SELECT clause The WHERE clause Probably the JOIN clauses too (but without knowing what you expect as output if a user has no city or category data, it's impossible to be sure) -
Can you attach a dump of your data?
-
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.
-
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.
-
Display list of records ordered by frequency of use
Barand replied to NotionCommotion's topic in PHP Coding Help
At the moment, then, they select an option but you don't store it with any data anywhere? -
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);
-
Display list of records ordered by frequency of use
Barand replied to NotionCommotion's topic in PHP Coding Help
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 -
Display list of records ordered by frequency of use
Barand replied to NotionCommotion's topic in PHP Coding Help
Then just count their usage over the last N months. -
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?
-
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
-
"Tour_name" should not be in the booking table, just the id
-
The you didn't do it right. Post current code
-
You need while (list($id, $name) = mysqli_fetch_row($result)) {
-
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.
-
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.
-
Why am I not getting the number of expected result through the loop?
Barand replied to Abel1416's topic in PHP Coding Help
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>';