-
Posts
24,602 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
-
What exactly does that mean? What happens, or doesn't happen.
-
If you stored your dates as something readable (like DATETIME) instead of using the unintelligible unix timestamps you would see that both those should appear on multiple days 2021-01-23 00:00:00 - 2021-01-30 00:00:00 2021-01-30 00:00:00 - 2021-02-01 00:00:00 Query each separate date is really inefficient. Get all for the month and store in an array. Then as you loop through the days, see if there are any events in the aray for that day and output them.
-
You need to read up on "variable scope". Variables inside a function are local to that function. If you want to use a variable from outside the function you need to pass it as an argument to the function (along with month and year). You need also to check queries for errors. The easiest way to do that is to put this line just before you make your connection to the database... mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); (edit) .... and turn php's error reporting on.
-
The first query is defined but not executed. The second query probably failed $sql = "SELECT * FROM $tablename WHERE $current_epoch BETWEEN start_day AND end_day"; ^^^^^^^^^^ Where is $tablename defined?
-
Mysql query, combine command about age and separate by gender
Barand replied to nitiphone2021's topic in MySQL Help
Using an "age_group" table as suggested and a test table with 999 random records ... +--------------+------------+--------+--------+ +--------+---------------+------+-----+---------+----------------+ | age_group_id | group_name | lo_age | hi_age | | Field | Type | Null | Key | Default | Extra | +--------------+------------+--------+--------+ +--------+---------------+------+-----+---------+----------------+ | 1 | Under 18 | 0 | 17 | | id | int(11) | NO | PRI | NULL | auto_increment | | 2 | 18 - 29 | 18 | 29 | | name | varchar(30) | YES | | NULL | | | 3 | 30 - 39 | 30 | 39 | | age | tinyint(4) | YES | | NULL | | | 4 | 40 - 49 | 40 | 49 | | gender | enum('M','F') | YES | | NULL | | | 5 | 50 - 59 | 50 | 59 | +--------+---------------+------+-----+---------+----------------+ | 6 | 60 - 69 | 60 | 69 | | 7 | 70 - 79 | 70 | 79 | | 8 | 80+ | 80 | 120 | +--------------+------------+--------+--------+ ... then ... SELECT group_name as `Age Group` , SUM(gender='M') as Male , SUM(gender='F') as Female , COUNT(*) as Total FROM tb_infected i JOIN age_group a ON i.age BETWEEN a.lo_age AND a.hi_age GROUP BY age_group_id; giving +------------+------+--------+-------+ | Age Group | Male | Female | Total | +------------+------+--------+-------+ | Under 18 | 70 | 98 | 168 | | 18 - 29 | 44 | 72 | 116 | | 30 - 39 | 42 | 50 | 92 | | 40 - 49 | 54 | 56 | 110 | | 50 - 59 | 47 | 62 | 109 | | 60 - 69 | 42 | 68 | 110 | | 70 - 79 | 36 | 68 | 104 | | 80+ | 76 | 114 | 190 | +------------+------+--------+-------+ -
You should have searched these forums for "calendar"...
-
Mysql query, combine command about age and separate by gender
Barand replied to nitiphone2021's topic in MySQL Help
I'd be tempted to have an age_group table (id, group_name, lo_age, hi_age) and join to that on if_age BEWEEN lo_age AND hi_age. It would save all those case statements and ensure consistency. BTW, your current age ranges exclude 80 year olds. -
PHP https with $_SESSION send to another page
Barand replied to nitiphone2021's topic in PHP Coding Help
No need. That happens automatically. It's a case of "set it, forget it" -
[PHP 7.4.13 ] imge uppload to database using PDO::
Barand replied to Sprint666l's topic in PHP Coding Help
That still isn't going to work! (unless you aren't using PDO as you stated) mysqli_query() is not a PDO method (the clue's in the name). Get into the habit of using prepared statements and not putting variables in the sql code. $insert = "UPDATE users SET profile_img = ? WHERE username = ?"; $stmt = $connect->prepare($insert); $stmt->execute( [ $filename, $_SESSION['username'] ] ); -
Sort the array first. Assuming you start with ... $options = [ [ 'type' => 'Visual disability', 'name' => 'Audio-described cut-scenes' ], [ 'type' => 'Visual disability', 'name' => 'Highlighted path to follow' ], [ 'type' => 'Physical disability', 'name' => 'Sensitivity settings for all the controls' ], [ 'type' => 'Visual disability', 'name' => 'Screen readers on menus' ], [ 'type' => 'Visual disability', 'name' => 'Slow down the game speed' ], ]; then ... # # Sort the array by type (descending) # usort($options, function($a, $b) { return $b['type'] <=> $a['type']; }); # # process the array # $prev_type = ''; // store previous type echo "<ul>\n"; foreach ($options as $opt) { if ($opt['type'] != $prev_type) { // is this a new type? if ($prev_type != '') { // was there a previous one? echo "</ul>\n</li>\n"; // if so, close it } echo "<li>{$opt['type']}\n<ul>\n"; $prev_type = $opt['type']; // store as previous value } echo "<li>{$opt['name']}</li>\n"; } // close last group echo "</ul>\n</li>\n"; // close whole list echo "</ul>\n"; giving ... <ul> <li>Visual disability <ul> <li>Audio-described cut-scenes</li> <li>Highlighted path to follow</li> <li>Screen readers on menus</li> <li>Slow down the game speed</li> </ul> </li> <li>Physical disability <ul> <li>Sensitivity settings for all the controls</li> </ul> </li> </ul> An alternative approach is to reorganise the array using subarrays for each type... $options = [ 'Visual disability' => [ 'Audio-described cut-scenes', 'Highlighted path to follow', 'Screen readers on menus', 'Slow down the game speed' ], 'Physical disability' => [ 'Sensitivity settings for all the controls' ] ]; then use two nested foreach() loops.
-
[PHP 7.4.13 ] imge uppload to database using PDO::
Barand replied to Sprint666l's topic in PHP Coding Help
If that is "fixed" then your testing is a little lax. Have you checked if the record is actually being updated (by magic, no doubt, as no query is executed)? -
You can store images in a database but it's not advised. Best way is store the image file in the file system and store the image location and metadata in the database.
-
Question about using a database connection class
Barand replied to kenoli's topic in PHP Coding Help
$this->pdo now contains your pdo connection. so $db = new DB; $stmt = $db->pdo->prepare(...) You should extra code to your class to set the connection's charset (UTF-8) and to set PDO::ATTR_EMULATE_PREPARES to false. It's also useful to set the PDO::ATTR_DEFAULT_FETCH_MODE attribute also. -
Change to $id = $_GET['id'] ?? DEFAULT_ID;
-
This is a pain in the bottom, everything should do as is.
Barand replied to guymclarenza's topic in PHP Coding Help
Probably because the inner loop's result object is overwriting the outer result object as you store them both in $query. But don't run queries inside loops like that . Use a single query with a join to get all the data in a single query. It's far more efficient. SELECT faqc_name , faq_id , faq_question FROM faq_cats c JOIN faqs f ON f.faq_cat = c.faqc_id WHERE faqc_site = :site ORDER BY faqc_id , faq_id -
PHP has array_product(). EG echo array_product([1, 2, 3, 8]); // 48 If you want to be able to supply separate arguments to a function instead of an array EG echo mul(1, 2, 3, 2, 4); then you can define the function as function mul(...$a) { return array_product($a); } echo mul(3,8,2); //48 echo mul(1,2,3,2,2,2) //48
-
https://lmgtfy.app/?q=Epidemiology+Databases
-
Trouble inserting post data into PDO prepared statements
Barand replied to kenoli's topic in PHP Coding Help
All you need is $insert_array = [ 'site_name' => 'asdfasdf', 'site_address' => 'Asdffads', 'description' => 'Asdfs', 'contact_phone' => 'Asdfsdaf' ]; $stmt = $conn->prepare("INSERT INTO Sites (site_name, site_address, description, contact_phone) VALUES (:site_name, :site_address, :description, :contact_phone) "); $stmt->execute($insert_array); -
Operations with variables from different arrays
Barand replied to cedricpatrick's topic in PHP Coding Help
One way would be to rename your input fields to something like name = 'jour[$jour][workday]' name = 'jour[$jour][startTime]' name = 'jour[$jour][endTime]' your posted data will then be nicely grouped Array ( [jour] => Array ( [1] => Array ( [workday] => 01/12/2020 [startTime] => 08:00 [endTime] => 06:00 ) [2] => Array ( [workday] => 02/12/2020 [startTime] => 08:30 [endTime] => 06:30 ) [3] => Array ( [workday] => 03/12/2020 [startTime] => 09:00 [endTime] => 04:30 ) . . . ) -
Student subject Positioning based on score using php and mysql database
Barand replied to Ponel's topic in PHP Coding Help
You are calculating the rank out of the whole population, not just the class. You need to include the class (armslevelid) in the groupings giving EDIT -- use code tags (<> button) -
Student subject Positioning based on score using php and mysql database
Barand replied to Ponel's topic in PHP Coding Help
-
Student subject Positioning based on score using php and mysql database
Barand replied to Ponel's topic in PHP Coding Help
9208 has 4 students with a higher grade and therefore must be rank"5" and not "4". (If 4 people beat you in a race, you are fifth, even if the 4 winners have the same times) As the rank is either equal to the previous rank or it is the sequence number, there is no way a rank will be more than the number of students. -
Student subject Positioning based on score using php and mysql database
Barand replied to Ponel's topic in PHP Coding Help
I give those with same total the same rank, otherwise they are ranked by their position in the sorted (DESC) results This the bit of the SQL that does it , @seq := CASE WHEN yss <> @prev THEN 1 ELSE @seq + 1 END as seq , @rank := CASE WHEN total = @prevtot THEN @rank ELSE @seq END as rank , @prevtot := total as total , @prev := yss as yss