Jump to content

Barand

Moderators
  • Posts

    24,615
  • Joined

  • Last visited

  • Days Won

    835

Everything posted by Barand

  1. Your "<script>..</script>" contains " characters that need escaping. It would take too long for my other thoughts on that code.
  2. Not in that query. BTW, why create yet another table which duplicates name data you already hold? You can quite easily get the names and slugs in those formats by querying the data you already hold. You are just wasting space, time and effort.
  3. try this version <?php const HOST = 'localhost'; ##### const USERNAME = '????'; # const PASSWORD = '????'; # const DATABASE = '????'; # These lines would # function pdoConnect($dbname=DATABASE) # normally be in { # $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); # an included file $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); # $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); # $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); # return $db; # } ##### /********************************* TEST DATA ***************************************** +---------+----------+------------+------------+----------+----------+------------+--------+ | post_id | topic_id | post_title | post_body | post_img | post_thb | posted | active | +---------+----------+------------+------------+----------+----------+------------+--------+ | 1 | NULL | Blog 1 | Blog one | NULL | NULL | 1605398400 | NULL | | 2 | NULL | Blog 2 | Blog two | NULL | NULL | 1607299200 | NULL | | 3 | NULL | Blog 3 | Blog three | NULL | NULL | 1607385600 | NULL | | 4 | NULL | Blog 4 | Blog four | NULL | NULL | 1608508800 | NULL | | 5 | NULL | Blog 5 | Blog five | NULL | NULL | 1608508800 | NULL | | 6 | NULL | Blog 6 | Blog six | NULL | NULL | 1609545600 | NULL | +---------+----------+------------+------------+----------+----------+------------+--------+ *************************************************************************************************/ $pdo = pdoConnect(); $today = new DateTime( $_GET['date'] ?? '' ); $prev = (clone $today)->modify('-1 month')->format('Y-m-d'); $next = (clone $today)->modify('+1 month')->format('Y-m-d'); $caption = $today->format('F Y'); $this_month = $today->format('n'); $day1 = (clone $today)->modify("first day of this month"); $queryStart = $day1->format('Y-m-d'); if ($day1->format('w') != 0) { $day1->modify('last Sunday'); } $dayN = (clone $today)->modify('last day of this month'); $queryEnd = $dayN->format('Y-m-d'); if ($dayN->format('w') != 6) { $dayN->modify('next sunday'); } $period = new DatePeriod($day1, new DateInterval('P1D'), $dayN); // calendar display dates ## ## get this month's blogs ## $blogs = []; $res = $pdo->prepare("SELECT post_id , date(from_unixtime(posted)) as day , post_title FROM DB_GRIMS_BLOG_POST WHERE date(from_unixtime(posted)) BETWEEN ? AND ? ORDER BY posted "); $res->execute( [ $queryStart, $queryEnd ] ); foreach ($res as $r) { if (!isset($blogs[$r['day']])) { $blogs[$r['day']] = []; } $blogs[$r['day']][] = $r; } ## ## Functions ## function calheads() { $out = '<tr>'; $days = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ]; foreach ($days as $d) { $out .= "<th abbr='$d' title='$d'>{$d[0]}</th>"; } return $out; } function caldata($per, $mth, &$blogs, $date) { $i = 0; $out = ''; foreach ($per as $d) { if ($i%7 == 0) { if ($out != '') $out .= "</tr>\n"; $out .= "<tr>"; } ++$i; $dno = $d->format('d'); $cls = $link = $title = $datablog = ''; $dbArr = []; if ($d->format('n') != $mth) { $cls .= 'blank '; } else { $cls .= 'daycell '; if ($d->format('Y-m-d') == date('Y-m-d')) $cls .= 'today '; if (isset($blogs[$d->format('Y-m-d')])) { $dayblogs = $blogs[$d->format('Y-m-d')]; $cls .= 'active '; if (count($dayblogs)==1) { $title = $blogs[$d->format('Y-m-d')][0]['post_title']; $dno = "<a href='https://whisperwillow.net/infusions/grims_blog/filtered.php?post_id={$blogs[$d->format('Y-m-d')][0]['post_id']}&date=$date'>$dno</a>"; } else { $title = join("\n", array_column($dayblogs,'post_title')); $cls .= 'multiblog '; foreach ($dayblogs as $dba) { $dbArr[$dba['post_id']] = $dba['post_title']; } $datablog = json_encode($dbArr); } } } $out .= "<td class='$cls' title='$title' data-blogs='$datablog'>$dno</td>\n"; } $out .= "</tr>\n"; return $out; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Examle calendar</title> <meta name="creation-date" content="12/06/2020"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script> <script type='text/javascript'> $().ready( function() { $(".multiblog").click( function() { var blogs = $(this).data('blogs') var date = $("#cal-date").val() $("#blogmenu").hide() $("#blogmenu").position({"Top":0, "Left":0}) $("#blogmenu").html("<b>Select blog:</b><br>") $.each(blogs, function(k,v) { $("#blogmenu").append("<p><a href='https://whisperwillow.net/infusions/grims_blog/filtered.php?post_id="+k+"&date="+date+"'>"+v+"</a></p>") }) var pos = $(this).position() $("#blogmenu").css("display","inline-block") $("#blogmenu").offset( {"top": pos.top+25, "left": pos.left} ) }) $("#blogmenu").click( function() { $("#blogmenu").html("<b>Select blog:</b><br>") $("#blogmenu").hide() $("#blogmenu").position({"Top":0, "Left":0}) }) }) </script> <style type='text/css'> body, table { font-family: arial, sans-serif; font-size: 14px; } table { border-collapse: collapse; width: 63%; margin: 50px auto; } caption { background-color: #A91723; color: #FFF; padding: 5px; text-align: center; font-size: 16px; } th { background-color: #5F8874; color: #FFF; padding: 2px; } td { background-color: #000; color: #FFF; padding: 2px; text-align: center; font-weight: 600; height: 22px; } td.active { background-color: #e3e3e3; color: #0000FC; } td.blank { background-color: #CCC; color: #FFF; } td.today { background-color: #07ABF6; } a { text-decoration: none;; } a:hover { text-decoration: underline;; } #navbtn1, #navbtn2 { font-weight: 600; color: #FFF; text-decoration: none; } #navbtn1 { float: left; } #navbtn2 { float: right; } #blogmenu { display: none; font-size: 14px; position: absolute; top: 0; left: 0; max-width: 200px; background-color: #FCF8E8; color: #000; padding: 4px; border: 2px solid #006EFC; } .multiblog { cursor: pointer; } </style> </head> <body> <input type='hidden' id='cal-date' value='<?=$today->format('Y-m-d')?>'> <table border='1'> <caption> <a id='navbtn1' href='?date=<?=$prev?>'>&lt;</a> <?=$caption?> <a id='navbtn2' href='?date=<?=$next?>'>&gt;</a> </caption> <thead> <?=calheads()?> </thead> <tbody> <?=caldata($period, $this_month, $blogs, $today->format('Y-m-d'))?> </tbody> </table> <div id='blogmenu'></div> </body> </html>
  4. INSERT INTO wp_terms (X, Y) ..... X and Y should be column names, not the data you want to put in them.
  5. Something like this? ... $rows = array_chunk(array_slice($files, 0, 9), 5); // get first 9 files, in chunks of 5 and 4 foreach ($rows as $row) { echo "<div class='row'>\n"; foreach ($row as $img) { $w = 100 / count($row); echo "<div class='image' style='width: $w%; '> <img src='$img' width='120px' > </div> "; } echo "</div>\n"; }
  6. What's your current code to produce the csv?
  7. Why do you insert the data into two tables The POST_TOPIC table merely duplicates data that is in the the POST table (art_mon and art_day are derived from posted value) +-------------+ | POST | +-------------+ | post_id |-------+ | topic_id |----+ | +----------------+ | post_title | | | | POST_TOPIC | | post_body | | | +----------------+ | post_img | | | | post_topic_id | | post_thb | | +--------| post_id | | posted |-+ +-----------| topic_id | | active | +--------------| art_mon | +-------------+ +--------------| art_day | +----------------+ You aren't doing yourself any favours by storing unix time value and separate month/day fields - just use a DATE type for posted (yyyy-mm-dd). Substitute this query into my code to use your table structure SELECT post_id , date(from_unixtime(posted)) as day , post_title FROM DB_GRIMS_BLOG_POST WHERE posted BETWEEN unix_timestamp(?) AND unix_timestamp(?) ORDER BY posted
  8. The manual says the fields should be type date or datetime, which I is why I tested it with a time field before posting. Maybe your version doesn't support time types (Mine is MySQL 5.7) Alternative... SELECT name , NOW() as Now , action_time , round(time_to_sec(timediff(action_time, time(now())))/60, 0) as mins FROM a_test_table; +--------+---------------------+-------------+------+ | name | Now | action_time | mins | +--------+---------------------+-------------+------+ | John | 2020-12-08 09:51:28 | 15:30:00 | 339 | | Paul | 2020-12-08 09:51:28 | 18:00:00 | 489 | | George | 2020-12-08 09:51:28 | 12:00:00 | 129 | | Ringo | 2020-12-08 09:51:28 | 10:00:00 | 9 | +--------+---------------------+-------------+------+
  9. It looks like you need to include config.php in register.php and not in register.php.
  10. Strange, ENT_IGNORE was added in v5.3. However its use is discouraged as a potential security risk. Try replacing ENT_IGNORE with NULL EDIT: As of 5.4, UTF-8 is the default so just go with htmlspecialchars($tagContent)
  11. $metaTagsHTML .= '<meta property="' . $propertyName . '" content="' . htmlspecialchars($tagContent,'ENT_IGNORE','UTF-8') . '" />' . "\n"; | | |__REMOVE__| ENT_IGNORE is a constant definition, not a string literal - remove the quotes.
  12. I've rewritten the code for you, cleaned up the structure cleaned up the HTML using classes and CSS and removed deprecated markup implemented mac_gyver's array suggestion implemented the links <?php const HOST = 'localhost'; ##### const USERNAME = '????'; # const PASSWORD = '????'; # const DATABASE = '????'; # These lines would # function pdoConnect($dbname=DATABASE) # normally be in { # $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); # an included file $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); # $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); # $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); # return $db; # } ##### /********************************* TEST DATA ***************************************** +---------+------------+--------+------------+ | blog_id | date | title | content | +---------+------------+--------+------------+ | 1 | 2020-11-15 | Blog 1 | Blog one | | 2 | 2020-12-07 | Blog 2 | Blog two | | 3 | 2020-12-08 | Blog 3 | Blog three | | 4 | 2020-12-10 | Blog 4 | Blog four | | 5 | 2020-12-21 | Blog 5 | Blog five | | 6 | 2021-01-02 | Blog 6 | Blog six | +---------+------------+--------+------------+ *************************************************************************************************/ $pdo = pdoConnect(); $today = new DateTime( $_GET['date'] ?? '' ); $prev = (clone $today)->modify('-1 month')->format('Y-m-d'); $next = (clone $today)->modify('+1 month')->format('Y-m-d'); $caption = $today->format('F Y'); $this_month = $today->format('n'); $day1 = (clone $today)->modify("first day of this month"); $queryStart = $day1->format('Y-m-d'); if ($day1->format('w') != 0) { $day1->modify('last Sunday'); } $dayN = $today->modify('last day of this month'); $queryEnd = $dayN->format('Y-m-d'); if ($dayN->format('w') != 6) { $dayN->modify('next sunday'); } $period = new DatePeriod($day1, new DateInterval('P1D'), $dayN); // calendar display dates ## ## get this month's blogs ## $blogs = []; $res = $pdo->prepare("SELECT blog_id , date as day , title FROM blog WHERE date BETWEEN ? AND ? ORDER BY date "); $res->execute( [ $queryStart, $queryEnd ] ); foreach ($res as $r) { $blogs[$r['day']] = $r; } ## ## Functions ## function calheads() { $out = '<tr>'; $days = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ]; foreach ($days as $d) { $out .= "<th abbr='$d' title='$d'>{$d[0]}</th>"; } return $out; } function caldata($per, $mth, &$blogs) { $i = 0; $out = ''; foreach ($per as $d) { if ($i%7 == 0) { if ($out != '') $out .= "</tr>\n"; $out .= "<tr>"; } ++$i; $dno = $d->format('d'); $cls = $link = $title = ''; if ($d->format('n') != $mth) { $cls .= 'blank '; } else { $cls .= 'daycell '; if (isset($blogs[$d->format('Y-m-d')])) { $cls .= 'active '; $title = $blogs[$d->format('Y-m-d')]['title']; $dno = "<a href='https://whisperwillow.net/infusions/grims_blog/filtered.php?post_id={$blogs[$d->format('Y-m-d')]['blog_id']}'>$dno</a>"; } if ($d->format('Y-m-d') == date('Y-m-d')) $cls .= 'today '; } $out .= "<td class='$cls' title='$title'>$dno</td>"; } $out .= "</tr>\n"; return $out; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Examle calendar</title> <meta name="creation-date" content="12/06/2020"> <style type='text/css'> body, table { font-family: verdana, sans-serif; font-size: 10pt; } table { border-collapse: collapse; width: 63%; margin: 50px auto; } caption { background-color: #A91723; color: #FFF; padding: 4px; text-align: center; font-size: 16pt; } th { background-color: #5F8874; color: #FFF; padding: 4px; } td { background-color: #EEE; padding: 8px; text-align: center; font-weight: 600; } td.active { background-color: #CCC; color: #FFF; } td.blank { background-color: #FFF; color: #CCC; } td.today { border-color: #A91723; border-width: 5px; color: #666; } #navbtn1, #navbtn2 { font-weight: 600; color: #FFF; text-decoration: none; } #navbtn1 { float: left; } #navbtn2 { float: right; } </style> </head> <body> <input type='hidden' id='caldata' value=''> <table border='1'> <caption> <a id='navbtn1' href='?date=<?=$prev?>'>&lt;</a> <?=$caption?> <a id='navbtn2' href='?date=<?=$next?>'>&gt;</a> </caption> <thead> <?=calheads()?> </thead> <tbody> <?=caldata($period, $this_month, $blogs)?> </tbody> </table> </body> </html> output:
  13. Try SELECT A FROM TableA LEFT OUTER JOIN TableB ON Table A. Column A = Table B. Column B AND Table A. Column A = Fixed value WHERE Column B IS NULL -- or -- SELECT A FROM TableA LEFT OUTER JOIN TableB ON Table A. Column A = Table B. Column B WHERE Table A. Column A = Fixed value AND Column B IS NULL Record selection conditions normally go in the WHERE clause. However, they can be in the JOIN's ON clause. If the condition were on a column in TableB (which is LEFT JOINed) then the condition would have to be in the ON clause.
  14. Can you define "doesn't work" for us. What should it do that it isn't doing? What is it doing that it shouldn't do?
  15. If you use MySql's timestampdiff() function you can go directly to minutes. DATA: +----+--------+-------------+ +-------------+-------------+------+-----+---------+----------------+ | id | name | action_time | | Field | Type | Null | Key | Default | Extra | +----+--------+-------------+ +-------------+-------------+------+-----+---------+----------------+ | 1 | John | 15:30:00 | | id | int(11) | NO | PRI | NULL | auto_increment | | 2 | Paul | 18:00:00 | | name | varchar(45) | YES | | NULL | | | 3 | George | 12:00:00 | | action_time | time | YES | | NULL | | | 4 | Ringo | 10:00:00 | +-------------+-------------+------+-----+---------+----------------+ +----+--------+-------------+ SELECT name , NOW() as Now , action_time , timestampdiff(MINUTE, now(), action_time) as mins FROM a_test_table; RESULTS: +--------+---------------------+-------------+------+ | name | Now | action_time | mins | +--------+---------------------+-------------+------+ | John | 2020-12-06 11:10:15 | 15:30:00 | 259 | | Paul | 2020-12-06 11:10:15 | 18:00:00 | 409 | | George | 2020-12-06 11:10:15 | 12:00:00 | 49 | | Ringo | 2020-12-06 11:10:15 | 10:00:00 | -70 | +--------+---------------------+-------------+------+
  16. Check for change events on the dropdown. Take appropriate action depending on whether its value changes to A or B.
  17. this worked $team = 65; $grade = 2020; $level = 1; /**** CSV CONTENT (export from Excel) uniform,nameFirst,nameLast,position,height 10,Laura,Norder,PG,"6'4""" 20,Tom,DiCanari,SF,"4'11""" ********************************************/ $sql = <<<SQL LOAD DATA LOCAL INFILE 'c:/inetpub/wwwroot/test/roster2.csv' INTO TABLE roster FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 ROWS (uniform, nameFirst, nameLast,position,@height) SET feet = substring_index(@height, '\'', 1) , inches = substring_index(substring_index(@height, '"', 1), '\'', -1) , team = $team , grade = $grade , level = $level SQL; $stmt = $my->query($sql); /**** TABLE: roster CREATE TABLE `roster` ( `roster_id` int(11) NOT NULL AUTO_INCREMENT, `team` int(11) DEFAULT NULL, `grade` int(11) DEFAULT NULL, `uniform` varchar(45) DEFAULT NULL, `nameFirst` varchar(45) DEFAULT NULL, `nameLast` varchar(45) DEFAULT NULL, `position` varchar(15) DEFAULT NULL, `feet` tinyint(4) DEFAULT NULL, `inches` tinyint(4) DEFAULT NULL, `level` int(11) DEFAULT NULL, PRIMARY KEY (`roster_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-----------+------+-------+---------+-----------+----------+----------+------+--------+-------+ | roster_id | team | grade | uniform | nameFirst | nameLast | position | feet | inches | level | +-----------+------+-------+---------+-----------+----------+----------+------+--------+-------+ | 1 | 65 | 2020 | 10 | Laura | Norder | PG | 6 | 4 | 1 | | 2 | 65 | 2020 | 20 | Tom | DiCanari | SF | 4 | 11 | 1 | +-----------+------+-------+---------+-----------+----------+----------+------+--------+-------+ */
  18. Ok, keep it a secret. Good luck.
  19. Your queries seem to be sprouting columns. What do the csv and your a_rosters table actually look like?
  20. then why have you defined the csv columns as (uniform,nameFirst,nameLast,position,@feet,@inches) ? With the mix of quotes in the SQL you would better using heredoc syntax when defining the query.
  21. That's why I laid it out the way I did with the comments - so it would be easy for you get the separate feet/inches values if you still wanted to go that way. [edit] Look more closely at my code - you require two substring_index()s to extract the inches. The inner to get the string before the final " and the outer one to get the string after the ' SET feet = substring_index(@height, '\'', 1) * 12 , inches = substring_index(substring_index(@height, '"', 1), '\'', -1)
  22. That said, here's a solution INPUT (roster.csv) uniform, firstname, lastname, position, height 101,Freda,Greaves,left out,6'4" 102,Jamie,Oliver,left behind,4'11" SQL LOAD DATA LOCAL INFILE 'c:/inetpub/wwwroot/test/roster.csv' INTO TABLE roster FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 ROWS (uniform, nameFirst, nameLast,position,@height) SET height = substring_index(@height, '\'', 1) * 12 -- feet + substring_index(substring_index(@height, '"', 1), '\'', -1) -- inches TABLE (roster) +-----------+---------+-----------+----------+-------------+--------+ | roster_id | uniform | nameFirst | nameLast | position | height | +-----------+---------+-----------+----------+-------------+--------+ | 1 | 101 | Freda | Greaves | left out | 76 | | 2 | 102 | Jamie | Oliver | left behind | 59 | +-----------+---------+-----------+----------+-------------+--------+
  23. Does the height of your player depend on which roster they are in? If a player is the same height no matter what roster s/he is placed in then the height columns should be in the player table, not the roster. In answer to your question, it is often useful to load csv data into an intermediate table then move it to the correct table using PHP, where you can use functions like explode(). Why have 2 columns (feet/inches) and not just convert to inches?
  24. If you had error reporting tuned on, you would see a message like this If the PHP processor comes across an unquoted string it assumes it is a defined constant. It then tries to find the value that was defined for that constant. If it cannot find one it then assumes it must be a string value 'green'. All this is a waste of time making your code less efficient, so always quote string literals.
  25. As an alterntive for $price = $res->fetchColumn(); return $price ? $price : 'Not set'; I could have used return $res->fetch()['price'] ?? 'Not set'; which might be better (if you have freebies and 0.00 is a valid price).
×
×
  • 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.