Jump to content

cobusbo

Members
  • Posts

    224
  • Joined

  • Last visited

Everything posted by cobusbo

  1. As requested I've tried something new with time() <html> <?php define('TIMEZONE', 'Africa/Harare'); date_default_timezone_set(TIMEZONE); $targetDate = new DateTime('2016-04-01 20:59:00'); $remaining = $targetDate->diff(new DateTime()); $now = time(); // not done if( $now > $targetDate ) { echo $remaining->format('%a D - %H:%I:%S'); //--> 86 D - 19:44:24 } // done else { header("Location: testlogin.php"); exit(); } ?> </html>
  2. That's just an example date I've tested it with current date and time
  3. Hi I'm trying to use my countdown timer to do a certain action when time is reach in this example I want to point users to another page, but seems like I'm going wrong somewhere along the way. When it reaches 0 it just starts counting up from 0 <html> <?php define('TIMEZONE', 'Africa/Harare'); date_default_timezone_set(TIMEZONE); $targetDate = new DateTime('2016-09-29 23:00:00'); $remaining = $targetDate->diff(new DateTime()); // not done if( $remaining > 0 ) { echo $remaining->format('%a D - %H:%I:%S'); //--> 86 D - 19:44:24 } // done else { header("Location: testlogin.php"); exit(); } ?> </html>
  4. Hi I'm trying to run a cron here to remove profile pictures delete users delete private messages delete messages but I need some help to make my code more clean and effective <?php include("chat_code_header.php"); //// Delete profile pictures and users id older than 30 days//// $querybd = "SELECT Username, last_online, pprofilepic FROM Users2 WHERE last_online < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))"; $resultbd = mysql_query($querybd) or die(mysql_error()); $users = array(); while($rowbd = mysql_fetch_array($resultbd)){ if ($rowbd['Username'] != '') $users[] = $rowbd['Username']; if($rowbd['pprofilepic'] == ""){}else{ $pprofilepic = realpath($rowbd['pprofilepic']); print "\n Pictures Removed:\n" . $pprofilepic . "\n"; unlink($pprofilepic); } } $list = implode('; ', $users); if($list == ""){printf ("Nobody Removed\n");}else{ print "\n Users Removed:\n" . $list . "\n"; } printf("Users Deleted: %d\n", mysql_affected_rows()); $sqldel = "DELETE Users2, StringyChat, pm, namechanges, kicksamount, broadcast, timeban FROM Users2 LEFT JOIN StringyChat ON Users2.mxitid = StringyChat.StringyChat_ip LEFT JOIN pm ON Users2.mxitid = pm.mxitid LEFT JOIN namechanges ON Users2.mxitid = namechanges.userid LEFT JOIN kicksamount ON Users2.mxitid = kicksamount.mxitid LEFT JOIN broadcast ON Users2.mxitid = broadcast.mxitid LEFT JOIN timeban ON Users2.mxitid = timeban.mxitid WHERE Users2.last_online < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))"; mysql_query($sqldel) or die("Error: ".mysql_error()); //// end of removal/// //// removal of messages//// $query = "DELETE FROM StringyChat WHERE StringyChat_time < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))"; mysql_query($query); printf("Messages deleted: %d\n", mysql_affected_rows()); //// removal of private messages//// $query1 = "DELETE FROM pm WHERE time < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))"; mysql_query($query1); printf("Private Messages deleted: %d\n", mysql_affected_rows()); ?>
  5. I know it would had been much easier to store it seperatly but the info is already stored like that for 900+ users so it will be difficult to reconfigure it like that without losing info and all the info is placed into an array by retrieving a header $_SERVER["HTTP_X_MXIT_PROFILE"]; so its not me cramming it all together
  6. Hi I got a column in my database containing profile information in an array form, but I want to select a specific part the gender of the person from the column and count the males and female values My database column contains the value en,ZA,1991-01-30,Male,1 I know I can explode the values like this $str = explode(',', $query); $answ = $str[3]; but I don't know how to implement it for the database to count the amount of values named Male and Female
  7. Yes I'm trying to run the script as a cron job every 24h http://xxxxxxxx/chat2/profile/images/resized_1380_1448867798.jpg Do I need to include the full path to unlink the file because in the previous I had a file in the profile folder which I just included the $rowbd['pprofilepic'] I will only be able to test the rest of the codes you gave me once there is a user to remove with an image
  8. Not helping <?php include("chat_code_header.php"); $querybd = "SELECT Username, last_online, pprofilepic FROM Users2 WHERE last_online < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))"; $resultbd = mysql_query($querybd) or die(mysql_error()); $users = array(); while($rowbd = mysql_fetch_array($resultbd)){ if ($rowbd['Username'] != '') $users[] = $rowbd['Username']; if($rowbd['pprofilepic'] == ""){}else{ $pprofilepic = "./profile/".$rowbd['pprofilepic']; print "\n Pictures Removed:\n" . $pprofilepic . "\n"; unlink($pprofilepic); } } $list = implode('; ', $users); if($list == ""){printf ("Nobody Removed\n");}else{ print "\n Users Removed:\n" . $list . "\n"; } printf("Users Deleted: %d\n", mysql_affected_rows()); $sqldel = "DELETE Users2, StringyChat, pm, namechanges, kicksamount, broadcast, timeban FROM Users2 LEFT JOIN StringyChat ON Users2.mxitid = StringyChat.StringyChat_ip LEFT JOIN pm ON Users2.mxitid = pm.mxitid LEFT JOIN namechanges ON Users2.mxitid = namechanges.userid LEFT JOIN kicksamount ON Users2.mxitid = kicksamount.mxitid LEFT JOIN broadcast ON Users2.mxitid = broadcast.mxitid LEFT JOIN timeban ON Users2.mxitid = timeban.mxitid WHERE Users2.last_online < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))"; mysql_query($sqldel) or die("Error: ".mysql_error()); $query = "DELETE FROM StringyChat WHERE StringyChat_time < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))"; mysql_query($query); printf("Messages deleted: %d\n", mysql_affected_rows()); $query1 = "DELETE FROM pm WHERE time < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))"; mysql_query($query1); printf("Private Messages deleted: %d\n", mysql_affected_rows()); ?> and output is as follow
  9. Hi im running a script to remove files from a directory but seems like I'm doing something wrong with the paths to the file First let me start with the field in my database. its stored as images/filename.jpg The fulle path to the file is chat2/profile/images/filename.jpg The file with the script im trying to run is in the chat2 folder I got the following stored in my script $pprofilepic = "../profile/".$rowbd['pprofilepic']; unlink($pprofilepic); but im getting the error
  10. Hi I have 2 tables I need to update according to the value of the 3rd table field currently I do 2 queries but I'm sure there must be a way to make it 1 query query 1 $sql = "UPDATE Room_users INNER JOIN Users2 u ON u.mxitid = Room_users.mxitid SET Room_users.User = u.Username"; query 2 $sql = "UPDATE Rooms INNER JOIN Users2 u ON u.mxitid = Rooms.mxitid SET Rooms.creator = u.Username"; How can I turn this into 1 query?
  11. $sql = "UPDATE `Room_users` SET `kick` = :kick WHERE kick < UNIX_TIMESTAMP()"; So this is my update query, normally I store the time in the kick field in unix format but there is cases where I store the value "Permanently" in that field as well is there a way to change the query to do nothing if the field value is "Permanently" but if the value is unix time then it should update the query?
  12. Ah sorry I found my problem I had $mod conflicting with another $mod
  13. Hi I'm trying to change my script from mysql to PDO but im struggling Here is my old Mysql code $queryadmin = "SELECT mxitid FROM Users2 WHERE rank = 1"; $resultadmin = mysql_query($queryadmin) or die(mysql_error()); $admin = array(); while($row = mysql_fetch_array($resultadmin)){ if ($row['mxitid'] != '') $admin[] = $row['mxitid']; } And here is my attempt to make it PDO $mod = "SELECT mxitid FROM Room_users WHERE Rank = 2"; $qmod = $conn->prepare($mod); $qmod->execute(); $qmod->setFetchMode(PDO::FETCH_ASSOC); $mod = array(); while ($rmod = $qmod->fetch()) { if ($rmod['mxitid'] != '') $mod[] = $rmod['mxitid']; } But it doesnt seem to work
  14. Table 1 (Rooms) id time Table 2 (Room_users) Roomid Table 3 (Room_chats) roomid this is the exact spelling and caps of the table names and column names. I need to delete all rows from table1,2 and 3 where table 2 and 3 column is the same as the id of table 1 if the current time is bigger than the time column in table 1 I checked all the caps cant seem to find any problem with it.
  15. Yes I checked the Roomid column name is in Caps just like in the query but I still get that error
  16. I tried $sqldel = "DELETE Rooms, Room_users, Room_chats FROM Rooms LEFT JOIN Room_users USING (Roomid) LEFT JOIN Room_chats USING (roomid) WHERE Rooms.time < UNIX_TIMESTAMP()"; // use exec() because no results are returned $conn->exec($sqldel); but getting the error Can you please check entry post #3 I posted an SQL dump of my database table setup...
  17. yes table 2 Room_chats might not have a matching record the current time woud be $time = date("U"); epoch time
  18. Doesn't seem to work $sqldel = "DELETE Rooms, Room_users, Room_chats FROM Rooms INNER JOIN Room_users USING (Roomid) INNER JOIN Room_chats USING (roomid) WHERE Rooms.time < :currenttime"; // use exec() because no results are returned $conn->exec($sqldel); Here is my database tables layout -- phpMyAdmin SQL Dump -- version 4.0.10deb1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Dec 10, 2015 at 05:42 PM -- Server version: 5.5.46-0ubuntu0.14.04.2 -- PHP Version: 5.5.9-1ubuntu4.14 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `spamchat` -- -- -------------------------------------------------------- -- -- Table structure for table `Rooms` -- CREATE TABLE IF NOT EXISTS `Rooms` ( `id` int(11) NOT NULL AUTO_INCREMENT, `room` varchar(30) NOT NULL, `pin` varchar(30) NOT NULL, `creator` varchar(30) NOT NULL, `mxitid` varchar(30) NOT NULL, `time` varchar(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -- Dumping data for table `Rooms` -- INSERT INTO `Rooms` (`id`, `room`, `pin`, `creator`, `mxitid`, `time`) VALUES (1, 'testing', '123', 'Cobusbo', 'Debater', ' 1449751215'), (2, 'testing', '123', 'Cobusbo', 'Debater', '1449836897'), (3, 'bleh', '123', 'Cobusbo', 'Debater', '1449754328'); -- -------------------------------------------------------- -- -- Table structure for table `Room_chats` -- CREATE TABLE IF NOT EXISTS `Room_chats` ( `id` int(11) NOT NULL AUTO_INCREMENT, `roomid` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `User` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `Message` varchar(1600) COLLATE utf8_unicode_ci NOT NULL, `Time` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `mxitid` varchar(30) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ; -- -- Dumping data for table `Room_chats` -- INSERT INTO `Room_chats` (`id`, `roomid`, `User`, `Message`, `Time`, `mxitid`) VALUES (1, '1', 'Cobusbo', '123', '1449769303', 'Debater'); -- -------------------------------------------------------- -- -- Table structure for table `Room_users` -- CREATE TABLE IF NOT EXISTS `Room_users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `User` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `mxitid` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `Room` varchar(160) COLLATE utf8_unicode_ci NOT NULL, `Roomid` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `Rank` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `kick` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `unid` varchar(30) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `unid` (`unid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=7 ; -- -- Dumping data for table `Room_users` -- INSERT INTO `Room_users` (`id`, `User`, `mxitid`, `Room`, `Roomid`, `Rank`, `kick`, `unid`) VALUES (1, 'Cobusbo', 'Debater', 'testing', '1', '1', '', 'Debater_1'), (2, 'Cobusbo', 'Debater', 'testing', '2', '1', '', 'Debater_2'), (4, 'Cobusbo', 'Debater', 'bleh', '3', '1', '', 'Debater_3'); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
  19. Hi I got 3 tables Table 1 id room pin creator mxitid time Table 2 id roomid user message time mxitid Table 3 id user mxitid room roomid rank kick unid Each room I create I place the new epoch time of when the room expire in Table 1 time field. But now im trying to create a script to check if my current time is bigger than the time in the Table 1 time field and if it is so it should delete the row in table 1, the rows in table 2 with the same roomid as the id of table 1 and the rows in table 3 with the same roomid as the id of table 1 How can I loop through all the records to delete the expired rooms info using PDO mysql?
  20. Hi, I'm recalling information from my database to show all the birthdays of the specific day but today the 30th of November 2015 I get a list of everyone who is stored in my database showing as if its their birthday. Somewhere I made a mistake my database field is DateTime $querybd = "SELECT Username, pdob FROM Users2"; $resultbd = mysql_query($querybd) or die(mysql_error()); $users = array(); while($rowbd = mysql_fetch_array($resultbd)){ if (date('m-d', strtotime($rowbd['pdob'])) == date('m-d')) $users[] = $rowbd['Username']; } $list = implode('; ', $users); if($list == ""){}else{ echo "<br><b>Todays Birthdays: </b>" . $list . "<br>"; } It worked fine till today
  21. Hi Im creating a countdown timer to show a result but I only want to show the result for x time then I want it to disappear, but seems like Somewhere I'm going wrong with my if functions any help... <html> <?php define('TIMEZONE', 'Africa/Harare'); date_default_timezone_set(TIMEZONE); $targetDate = new DateTime('2015-11-24 11:57:00'); $runningDate = new DateTime('2015-11-24 12:08:00'); $time = new DateTime(); $remaining = $targetDate->diff(new DateTime()); // not done if( $time < $targetDate ) { echo $remaining->format('%a D - %H:%I:%S'); //--> 86 D - 19:44:24 } // done elseif($targetDate < $runningDate ) { print "The time has been reached show this messagt till runningdate is reached"; } elseif($time > $runningDate ) { print ""; }else{ print ""; } ?> </html>
  22. Yes but I wish to know if my code will work. Should it be in the while loop? to unlink each record that is older than 30 days and remove those specific records from the database?
×
×
  • 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.