Jump to content

Barand

Moderators
  • Content Count

    18,927
  • Joined

  • Last visited

  • Days Won

    350

Everything posted by Barand

  1. Barand

    subtract a month from a date()

    If you had used it on the 26th November, 2018 it would
  2. Barand

    PHP TIME (NOT TIMEDATE) difference

    My preference is to use dateTime functions foreach ($data as $period => $times) { echo "$period " . calcDiff($times[0], $times[1]) . '<br>'; } function calcDiff($tstr1, $tstr2) { $t1 = new DateTime($tstr1); $t2 = new dateTime($tstr2); if ($t2 < $t1) $t2->modify('+1 days'); $diff = $t2->diff($t1); return sprintf('%d:%02d:%02d', $diff->h, $diff->i, $diff->s); } giving days 8:45:00 nights 10:45:00
  3. Barand

    subtract a month from a date()

    I always find it a lot easier and more intuitive to just use something like CURDATE() + INTERVAL 5 DAY rather than using the DATE_ADD() and DATE_SUB() functions
  4. Barand

    subtract a month from a date()

    The problem you stated was that you had a date of 27th January and want to delete those before the start of the previous month. That is not the same as just subtracting 1 month or 30 days. Which is it? [edit] if you just want to delete everything older than 1 month you don't need php DELETE FROM mytable WHERE recorddate < CURDATE() - INTERVAL 1 MONTH
  5. Barand

    subtract a month from a date()

    Your default timezone should be set in your php.ini file (see example below) Alternatively, you need to set it in your program before call ing any datetime functions EG date_default_timezone_set("Europe/London");
  6. Just guessing, but it looks as though 34 may be the id of the record containing the image to be deleted. Therefore you need to retrieve record 34 to get the image file name unlink the image file delete record 34
  7. That javascript ajax call is sending the id in $_POST['object_id'], not in $_POST['image']
  8. Barand

    subtract a month from a date()

    If it's shared hosting it could be that they have disabled phpinfo() for security reasons. DateTime should be available though with your version of php (even though it is several years old). You still haven't told me if the amendment to your code that I posted is working. (You are still posting "echo $date")
  9. "image" may be the column name in your database but, what matters here, it isn't the name of one of the form inputs that you are POSTing. You can use this to see what is being posted echo '<pre>', print_r($_POST, 1), '</pre>';
  10. Barand

    month/date with leading zero

    "age" would go in the SELECT clause, along with other columns you are selecting. (whatever you want in the query output goes there) For example ... SELECT fname , lname , dob , timestampdiff(YEAR, dob, curdate()) as age FROM pupil ORDER BY age; +----------+------------+------------+------+ | fname | lname | dob | age | +----------+------------+------------+------+ | Peter | Appleby | 2003-04-23 | 15 | | Mary | Whitehouse | 2002-09-06 | 16 | | Adam | Simms | 2001-06-22 | 17 | | Allan | Blair | 2001-03-04 | 17 | | Anna | Hamilton | 2002-01-16 | 17 | | Anne | Bailey | 2001-08-02 | 17 | | Anthony | Bell | 2001-10-04 | 17 | | David | Powell | 2001-05-03 | 17 | | Emma | Watson | 2001-11-20 | 17 | | George | Wilson | 2001-06-30 | 17 | | Henry | Irving | 2001-08-12 | 17 | | Jane | Morrison | 2001-08-24 | 17 | | John | Patterson | 2001-09-06 | 17 | | John | Tully | 2001-09-03 | 17 | | John | Watson | 2001-09-30 | 17 | | Margaret | Norton | 2001-04-23 | 17 | | Mary | Sheldon | 2001-06-14 | 17 | | Michael | Grove | 2001-08-11 | 17 | | Peter | Adamson | 2001-09-18 | 17 | | Wayne | Jones | 2001-05-06 | 17 | | William | Smith | 2001-12-08 | 17 | | Caroline | Freeman | 2000-12-13 | 18 | | Jack | Williams | 2000-09-06 | 18 | | Mary | Blake | 1999-10-04 | 19 | +----------+------------+------------+------+ To see who share the same birthday ... SELECT RIGHT(dob,5) as mthday , GROUP_CONCAT(fname,' ',lname, ' (', timestampdiff(YEAR, dob, curdate()) , ')' SEPARATOR ' / ') as pupils FROM pupil GROUP BY RIGHT(dob,5) HAVING COUNT(*) > 1; +--------+-----------------------------------------------------------------+ | mthday | pupils | +--------+-----------------------------------------------------------------+ | 04-23 | Margaret Norton (17) / Peter Appleby (15) | | 09-06 | John Patterson (17) / Jack Williams (18) / Mary Whitehouse (16) | | 10-04 | Anthony Bell (17) / Mary Blake (19) | +--------+-----------------------------------------------------------------+
  11. That is telling you that you are attempting to delete a path with no file name, just the directory. There is no file name because $_POST['image'] does not exist, which is what the othere message tells you
  12. Barand

    subtract a month from a date()

    Sounds like your php installation is seriously FUBAR
  13. Barand

    subtract a month from a date()

    check output from phpinfo(). Is date support enabled?
  14. Barand

    subtract a month from a date()

    Did echoing using the $date->format() method work?
  15. Barand

    subtract a month from a date()

    That IS PHP code so why is it a problem?. (Unless you are using a php version prior to 5.2!) Try <?php $date = new DateTime('first day of last month'); echo $date->format('Y-m-d'); ?> Do you have error reporting turned on?
  16. Barand

    subtract a month from a date()

    $date = new DateTime('first day of last month'); $stmt = $pdo->prepare("DELETE FROM mytable WHERE recorddate < ?"); $stmt->execute( [$date->format(Y-m-d)] ); Make sure dates stored in your database are in the correct yyyy-mm-dd format
  17. Barand

    PDO double entries

    I don't have the full array I have shown you how to do it
  18. Barand

    month/date with leading zero

    Why don't you look at the example that Kicken posted?
  19. Barand

    Best approach guidance

    it simply takes the rightmost 5 characters from a string value, such as a (correctly stored) date 2019-01-23 If they are the same in both dates (dob and today), then "Happy Birthday"
  20. Barand

    Best approach guidance

    You should be able to work out from the previos reply that it is their birthday if RIGHT(CURRENT_DATE, 5) = RIGHT(date_of_birth, 5) or if you do it in PHP substr($row['date_of_birth'], -5) == date('m-d')
  21. Give this a try // CREATE OUTPUT TABLE score $db->exec("CREATE TABLE IF NOT EXISTS score ( score_id int not null auto_increment primary key, user_id int, skill_id int, rank bigint(12) , level bigint(12) , xp bigint(12) , date date ) "); $query = $conn->query("SELECT user_id, name FROM users LIMIT 1"); $row = $query->fetch(PDO::FETCH_ASSOC); $uid = $row['user_id']; $anme = $row['name']; $url = 'https://secure.runescape.com/m=hiscore/index_lite.ws?player='. $name ; //api that the csv data is coming from $highscores = file_get_contents($url); // <--- substituting data from forum post $placeholders = []; $values = []; $lines = explode("\n", $highscores); $skill = 0; foreach ($lines as $line) { if (strpos($line, '-1')!==false) continue; // ignore lines with -1 value if (trim($line) == '') continue; $linevals = array_filter(explode(',', $line)); $placeholders[] = "(?,?,?,?,?,?)"; array_push($values, $uid, ++$skill, date('Y-m-d'), ...$linevals); } // INSERT ALL 29 ROWS WITH SINGLE INSERT QUERY $insert = $db->prepare("INSERT INTO score (user_id, skill_id, date, rank, level, xp) VALUES " . implode(',', $placeholders)); $insert->execute($values) ;
  22. We'll find out when I try to process it. [edit] I split the data you posted into lines of 3 values. You said 27 but there are 28 before it starts getting weird.
  23. Are those really spaces between each set of three values or are they linefeeds (\n)? HTML has a way treating all whitespace as a space.
  24. I still don't know what the data you are processing looks like. Unless, if you echo $highscores, it gives 123456(rank compared to all other players), 58(level of the skill), 1234567(total xp in skill),
×

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.