brokenmech Posted February 3, 2010 Share Posted February 3, 2010 I'm trying to create a recent activity column for my php motion site. I'm probably doing it all wrong, but I'm stuck trying to insert the recent activity events into a table. Here is my code so far: /* Works out the time since the entry post, takes a an argument in unix time (seconds) */ function time_since($original) { // array of time period chunks $chunks = array( array(60 * 60 * 24 * 365 , 'year'), array(60 * 60 * 24 * 30 , 'month'), array(60 * 60 * 24 * 7, 'week'), array(60 * 60 * 24 , 'day'), array(60 * 60 , 'hour'), array(60 , 'minute'), ); $today = time(); /* Current unix time */ $since = $today - $original; // $j saves performing the count function each time around the loop for ($i = 0, $j = count($chunks); $i < $j; $i++) { $seconds = $chunks[$i][0]; $name = $chunks[$i][1]; // finding the biggest chunk (if the chunk fits, break) if (($count = floor($since / $seconds)) != 0) { // DEBUG print "<!-- It's $name -->\n"; break; } } $print = ($count == 1) ? '1 '.$name : "$count {$name}s"; if ($i + 1 < $j) { // now getting the second item $seconds2 = $chunks[$i + 1][0]; $name2 = $chunks[$i + 1][1]; // add second item if it's greater than 0 if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) { $print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s"; } } return $print; } $br = "<br>"; //Get most recent video comment $sql ="SELECT indexer, by_id, by_username, video_id, todays_date FROM videocomments ORDER BY indexer DESC LIMIT 1 "; $query = @mysql_query($sql); $result = @mysql_fetch_array($query); $member_username = $result['by_username']; $video_id = $result['video_id']; $todays_date = $result['todays_date']; $todays_date = strtotime($todays_date); $todays_date = time_since($todays_date); $sql ="SELECT title FROM videos WHERE indexer = '$video_id'"; $query = @mysql_query($sql); $result = @mysql_fetch_array($query); $video_title = $result['title']; $recent_event = $member_username." commented on the video " .$video_title. $br. $todays_date. " ago".$br.$br; echo $recent_event; $sql ="INSERT INTO recent_activity........... Can someone show me how to insert this variable into the table? The recent_activity table has two columns... indexer(auto increment) and recent_events. Also if I am doing this all wrong can someone show me a better way to do it. echo $recent_event; is brokenmech [admin] commented on the video Angel's tricks 1 hour, 29 minutes ago Link to comment https://forums.phpfreaks.com/topic/190744-having-trouble-with-insert/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.