-
Posts
24,605 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
Get list of values from two connected listboxes
Barand replied to BrandonMoore's topic in PHP Coding Help
If I understand what you're saying Show available counties in ListA Drag some counties from ListA to ListB When counties are selected in ListB, add them to ListC You stated you are doing a database search. Do you then want to submit ListC to search for items in those counties? -
Use the reference manual at php.net. It's always up-to-date and I believe there is a US version available.
-
The first query is returning neither a count of records nor an array - it returns a result object $q = "SELECT COUNT(*) FROM $db_table"; $res = $pdo->query($q); $num = $res->fetchColumn(); However, that code is totally superfluous - you don't need the count just to get a random record. $q = "SELECT quote,author FROM quotes ORDER BY RAND() LIMIT 1";
-
$num will not contain the record count. Why is that $num being used in the call to RAND() function?
-
You engineered it. When you started citing me in your posts as being responsible for the original code you gave me two undesirable options... I could carry on ignoring the posts, but then I would look bad in everyone's eyes for being the one who knew the code but apparently leaving you in the lurch, or I could submit to your coercion to make me carry on helping you with the project, albeit via the forum. When on the horns of a dilemma one looks for a third option. And should I be grateful for your selling my code without my permission and generously offering me 50%?
-
Save jarvis's latest code in "/htdocs/book.php" then try this in your browser's address bar http://localhost/book.php?title=War+and+Peace&author=Tolstoy and see if that works.
-
It displays an interactive map of his association's marina, showing all the berths and the boats in each berth. Clicking on a boat displays details of the boat and (if the user is logged in as a member) it displays contact details of the boat owner. It also allows you move boats from one berth to another, or from the waiting lists at the bottom to an empty berth. All changes update the database. Having made a change the map is redrawn. As you can see from the image below, it worked when it left the shop (login too, so it can display the owner details). I wrote this, and a few other pages, for Leon as a hobby project during the lockdown. If you examine the lower right-hand edge of the image you will see my name. When he put it on his site that name had been removed and he added footer proclaiming "Design and Development by...<his site>". If you look at the posted code (line 300 - about halfway down - my name is there but now commented out). I told him that as he wanted to claim all the credit for the design and developent then he should actually do it all. I then ceased communication. Given that history, it seems strange he should be publically crediting me now he has screwed with the code and it has all gone FUBAR. Whether he intends it as blame or just to try and embarrass me into helping out, I'm not sure. But it does give me no choice but to explain publically why I am not rushing forward to help with his problems.
-
compare csv files data and create new one in php
Barand replied to priyank199's topic in PHP Coding Help
I have no idea what I am looking in that example. Abstract examples seldom work. Am I looking at one record from each csv, or eight records from the first csv and six from the second Perhaps you could post the first 10 records from each csv so I can see what the data looks like. -
compare csv files data and create new one in php
Barand replied to priyank199's topic in PHP Coding Help
What have you tried? -
You could save the output as an image file and import that into the PDF file. FPDF supports png, jpeg, gif TCPDF supports the above plus SVG images (and you can also embed SVG script into the PDF)
-
The dbfiddle link that was in your post when I tried it had two sets of "..." in the middle of the reference. The one that's there now is not the original.
-
I'm sorry you find that request difficult to comprehend. If I can see the data I might be able to work out why you are getiing the problem with that query. Without the data I will have to create the tables myself, but as I don't yet know the cause, I cant add data that is going to cause the problem. But as you are unwilling to help me to you with your problem, I'll bow out now. Good luck.
-
That dbfidlle link is as much use as a chocolate teapot.
-
Can you you provide some test data for those two tables that exhibits this problem?
-
The data looks OK. It could do with some separation between the blocks of student data to make it easier to read. Perhaps... foreach($results_by_date as $name => $work) { foreach($work as $kdate => $date) { if($kdate == 'date'){ echo str_repeat('-', 20)."\n" ; echo $date. "\n\n"; }else{ foreach($date as $kdata => $date_data){ foreach($date_data as $kdatakey => $data){ echo " " . $data. "\n"; } echo " \n" ; } } } } FYI, this is my version for cli output // JSON from previous script saved in file $results = json_decode(file_get_contents('c:/inetpub/wwwroot/test/doc1355/rohan.json'), 1); $pad = str_repeat(' ', 8); $divs = $pad . str_repeat('-', 12) . PHP_EOL; $divd = str_repeat('-', 20) . PHP_EOL; echo '<pre>'; // test only - not required in CLI mode foreach ($results as $day) { echo $day['date'] . PHP_EOL . PHP_EOL; foreach ($day['students'] as $k => $sdata) { if ($k) echo $divs; foreach ($sdata as $val) { echo $pad . $val . PHP_EOL; } } echo $divd; }
-
It fails if the output values from the the new test script don't match the original table's values. For example, the output from my test script, built from the JSON data, looks like this (which can be easily compared with the original) ... You aren't compelled to use my method. Feel free to think up your own.
-
One way to test it would be to work backwards from the JSON. Decode the JSON string and recreate a table from its data so you can visually compare the results with a display or print of the original. It would be too tricky to recreate something as bad as the original so go for something simpler, say If you want to test it in CLI mode, then, unless you want the extra fun of drawing grids on the screen, you could go for a simple column display, such as
-
As far as I can see, they appear consistent within each block. But there is no way of knowing - if the times were reversed, who could know which was which? The best processor for this table is a document shredder.
-
The proof of the pudding is in the eating... (Line 72 applies the labels to the student data) $html = file_get_contents('c:/inetpub/wwwroot/test/doc1355/rohan.html'); // the table html $ranges= [[ 'start' => [ 'r'=>5, 'c'=>0 ], // DATES 'end' => [ 'r'=>5, 'c'=>21 ], 'labels'=> ['date'] ], [ 'start' => [ 'r'=>6, 'c'=>0 ], 'end' => [ 'r'=>11, 'c'=>21 ], 'labels'=> [ 'student_id', 'report_time', 'leaving-time', 'office', 'other', 'first_race'] ], [ 'start' => [ 'r'=>13, 'c'=>0 ], 'end' => [ 'r'=>18, 'c'=>21 ], 'labels'=> [ 'student_id', 'report_time', 'other', 'office', 'leaving-time', 'first_race'] ], [ 'start' => [ 'r'=>19, 'c'=>0 ], 'end' => [ 'r'=>24, 'c'=>21 ], 'labels'=> [ 'student_id', 'report_time', 'other', 'office', 'leaving-time', 'first_race'] ], [ 'start' => [ 'r'=>25, 'c'=>0 ], 'end' => [ 'r'=>30, 'c'=>21 ], 'labels'=> [ 'student_id', 'report_time', 'other', 'office', 'leaving-time', 'first_race'] ]]; foreach ($ranges as $range) { $results[] = getColumns($html, $range); } $results_by_date = getResultsByDate($results); function getResultsByDate($results) { $res = []; foreach ($results[0] as $kc => $date) { $res[$kc] = [ 'date' => $date['date'], 'students' => [] ]; } for ($i=1; $i<=4; $i++) { foreach ( $results[$i] as $kc => $sdata) { #if (ctype_digit($sdata[0]) || $sdata[0]=='N/A') { if (!empty($sdata['student_id']) && $sdata['student_id'] != ' ') { $res[$kc]['students'][] = $sdata; } } } // remove dates with no students $res = array_filter($res, function($v) { return !empty($v['students']); }); return $res; } function getColumns(&$html, $range) { $rows = []; $kr = 0; $p1 = 0; // find first row in out range for ($r=0; $r<=$range['start']['r']; $r++) { $p1 = strpos($html, '<tr', $p1); ++$p1; } $p1--; for ($kr=$range['start']['r']; $kr<=$range['end']['r']; $kr++) { $rows[$kr] = getCells($html, $range, $p1); $p1 = strpos($html, '<tr', $p1+1); } $cols = []; for ($kc=$range['start']['c']; $kc<=$range['end']['c']; $kc++) { $cols[] = array_combine($range['labels'], array_column($rows, $kc)); // ASSIGN THE LABELS TO THE DATA } return $cols; } function getCells(&$html, $range, $p1) { $cells = []; for ($kc=$range['start']['c']; $kc<=$range['end']['c']; $kc++) { $p1 = strpos($html, '<td', $p1+1); $p1 = strpos($html, '>', $p1+1); $p2 = strpos($html, '<td', $p1); $cells[$kc] = trim(strip_tags(substr($html, $p1+1, $p2-$p1-1))); } return $cells; } echo '<pre>' . print_r($results_by_date, 1) . '</pre>'; Gives Array ( [0] => Array ( [date] => May29Tue [students] => Array ( [0] => Array ( [student_id] => N/A [report_time] => [leaving-time] => [office] => [other] => [first_race] => ) ) ) [1] => Array ( [date] => May30Wed [students] => Array ( [0] => Array ( [student_id] => AAVL [report_time] => 06:00 [leaving-time] => 14:00 [office] => [other] => [first_race] => ) ) ) [2] => Array ( [date] => May31Thu [students] => Array ( [0] => Array ( [student_id] => 8751 [report_time] => 03:55 [leaving-time] => 04:55 [office] => WFH [other] => COMP AVL [first_race] => 08:00 ) [1] => Array ( [student_id] => 8752 [report_time] => 08:35 [other] => COMP AVL [office] => WFH [leaving-time] => 11:55 [first_race] => 12:25 ) ) ) ... etc ... or if you want the json output echo json_encode($results_by_date); [{"date":"May29Tue","students":[{"student_id":"N\/A","report_time":" ","leaving-time":" ","office":" ","other":" ","first_race":" "}]},{"date":"May30Wed","students":[{"student_id":"AAVL","report_time":"06:00","leaving-time":"14:00","office":" ","other":" ","first_race":" "}]},{"date":"May31Thu","students":[{"student_id":"8751","report_time":"03:55","leaving-time":"04:55","office":"WFH","other":"COMP AVL","first_race":"08:00"},{"student_id":"8752","report_time":"08:35","other":"COMP AVL","office":"WFH","leaving-time":"11:55","first_race":"12:25"}]},{"date":"Jun01Fri","students":[{"student_id":"8462","report_time":"04:30","leaving-time":"05:30","office":"WFH","other":"COMP NOT AVL","first_race":"07:10"},{"student_id":"8465","report_time":"07:45","other":"COMP NOT AVL","office":"WFH","leaving-time":"09:20","first_race":"09:50"}]},{"date":"Jun02Sat","students":[{"student_id":"CBSE","report_time":"02:00","leaving-time":"10:00","office":" ","other":" ","first_race":" "}]},{"date":"Jun03Sun","students":[{"student_id":"N\/A","report_time":" ","leaving-time":" ","office":" ","other":" ","first_race":" "}]},{"date":"Jun04Mon","students":[{"student_id":"N\/A","report_time":" ","leaving-time":" ","office":" ","other":" ","first_race":" "}]},{"date":"Jun05Tue","students":[{"student_id":"N\/A","report_time":" ","leaving-time":" ","office":" ","other":" ","first_race":" "}]},{"date":"Jun06Wed","students":[{"student_id":"N\/A","report_time":" ","leaving-time":" ","office":" ","other":" ","first_race":" "}]},{"date":"Jun07Thu","students":[{"student_id":"N\/A","report_time":" ","leaving-time":" ","office":" ","other":" ","first_race":" "}]},{"date":"Jun08Fri","students":[{"student_id":"8113","report_time":"05:05","leaving-time":"06:05","office":"WFH","other":"ZRH","first_race":"07:50"},{"student_id":"8114","report_time":"08:25","other":"ZRH","office":"WFH","leaving-time":"10:10","first_race":" "},{"student_id":"8277","report_time":"11:05","other":"WFH","office":"MAD","leaving-time":"13:40","first_race":"14:10"}]},{"date":"Jun09Sat","students":[{"student_id":"8274","report_time":"04:00","leaving-time":"05:00","office":"MAD","other":"WFH","first_race":"07:25"},{"student_id":"8221","report_time":"08:10","other":"WFH","office":"VLC","leaving-time":"10:30","first_race":" "},{"student_id":"8222","report_time":"11:05","other":"VLC","office":"WFH","leaving-time":"14:00","first_race":"14:30"}]},{"date":"Jun10Sun","students":[{"student_id":"N\/A","report_time":" ","leaving-time":" ","office":" ","other":" ","first_race":" "}]},{"date":"Jun11Mon","students":[{"student_id":"N\/A","report_time":" ","leaving-time":" ","office":" ","other":" ","first_race":" "}]},{"date":"Jun12Tue","students":[{"student_id":"AAVL","report_time":"05:15","leaving-time":"13:15","office":" ","other":" ","first_race":" "}]},{"date":"Jun13Wed","students":[{"student_id":"8973","report_time":"04:05","leaving-time":"05:05","office":"WFH","other":"SOF","first_race":"08:05"},{"student_id":"8974","report_time":"08:50","other":"SOF","office":"WFH","leaving-time":"12:10","first_race":"12:40"}]},{"date":"Jun14Thu","students":[{"student_id":"ADTY","report_time":"09:30","leaving-time":"16:30","office":" ","other":" ","first_race":" "}]},{"date":"Jun15Fri","students":[{"student_id":"8233","report_time":"12:25","leaving-time":"13:25","office":"WFH","other":"SSP","first_race":"15:40"},{"student_id":"8237","report_time":"16:10","other":"SSP","office":"WFH","leaving-time":"18:25","first_race":"18:55"}]},{"date":"Jun16Sat","students":[{"student_id":"N\/A","report_time":" ","leaving-time":" ","office":" ","other":" ","first_race":" "}]},{"date":"Jun17Sun","students":[{"student_id":"N\/A","report_time":" ","leaving-time":" ","office":" ","other":" ","first_race":" "}]},{"date":"Jun18Mon","students":[{"student_id":"807","report_time":"11:35","leaving-time":"12:35","office":"WFH","other":"OMV","first_race":"14:10"},{"student_id":"808","report_time":"14:35","other":"OMV","office":"WFH","leaving-time":"16:15","first_race":" "},{"student_id":"837","report_time":"16:50","other":"WFH","office":"BFS","leaving-time":"18:25","first_race":" "},{"student_id":"840","report_time":"18:55","other":"BFS","office":"WFH","leaving-time":"20:25","first_race":"20:55"}]},{"date":"Jun19Tue","students":[{"student_id":"8551","report_time":"10:50","leaving-time":"11:50","office":"WFH","other":"MJV","first_race":"14:30"},{"student_id":"8552","report_time":"15:00","other":" ","office":"WFH","leaving-time":"17:40","first_race":" "},{"student_id":"8187","report_time":"18:55","other":"WFH","office":"LIN","leaving-time":"20:50","first_race":"21:20"}]}]
-
The label arrays define the data pattern for each block
-
I'd assumed they'd given someone 15 minutes html training and told them to construct the table of student data manually.
-
The only way I can see of doing it is to supply the labels to be applied when you define the data blocks For example [ 'start' => [ 'r'=>6, 'c'=>0 ], 'end' => [ 'r'=>11, 'c'=>21 ], 'labels'=> [ 'student_id', 'report_time', 'leaving-time', 'office', 'comp_avl', 'first_race'] ] Thats strange. It's one of things I pointed out right at the start - I said there was no consistency in the data.
-
The point is you can't apply the same set of field names because the data appears to be randomly ordered for each block of students. Where they the same text (like "COMP AVL") sometimes it's the third item, sometimes it's the fifth. (Why do you think you got the Award Certificate?) See example in my previous post.
-
[{"student_id":"AAVL","report_time":"06:00","leaving_time":"14:00", ... ^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^ How are you getting those field names into the data? There is no consistent pattern in the data blocks and no labels. For example [date] => May31Thu [students] => Array ( [0] => Array ( [0] => 8751 Student [1] => 03:55 2 times [2] => 04:55 [3] => WFH 2 texts [4] => COMP AVL [5] => 08:00 1 time ) [1] => Array ( [0] => 8752 Student [1] => 08:35 1 time [2] => COMP AVL 2 texts [3] => WFH [4] => 11:55 2 times [5] => 12:25 ) )