Twitter Clone MySQL Assignment

From Knowledge Kitchen
Jump to navigation Jump to search

For this assignment, you will recreate Twitter. Create a page where users are able to post status updates (limited to 140 characters, of course). Once posted, these updates appear in reverse chronological order on the page. Do not worry about creating user accounts. All posts are anonymous.

Users can flag any post as being inappropriate. An administrator page shows those posts that have been flagged, and allows the administrator to either delete or ignore those posts.


Download an interactive prototype of these wireframes here:

Home page

Mysql read write assignment fall2013 home wireframe.png

Admin page

Mysql read write assignment fall2013 admin wireframe.png

Useful PHP functions

Dealing with time

  • time() function gives you the current time in (number of seconds since January 1, 1970)
  • strtotime() function allows you to convert a nice string-formatted time into a UNIX timestamp version of that time.
  • gmdate() function allows you to nicely format unix timestamps into strings displaying GMT-format dates.

To calculate how long ago a given post was created:

//loop through each row
while ($row = $result->fetch_assoc()) { 

	$currentDateGMT = gmdate("Y-m-d\TH:i:s\Z", time()); //current date in GMT
	$postDateGMT = gmdate("Y-m-d\TH:i:s\Z", strtotime($row['created'])); //created date in GMT
	$dateDiffInSeconds = strtotime($currentDateGMT) - strtotime($postDateGMT); //difference in seconds between the two dates
	$dateDiffInHours = floor($dateDiffInSeconds / 3600); //difference in hours between the two dates

	//output a paragraph with the info
	print <<<END
 The current date is {$currentDateGMT} in GMT.<br />
 The post was created at {$postDateGMT} in GMT.<br />
 That's a difference of {$dateDiffInSeconds} minutes, or {$dateDiffInHours} hours. <br />


Extra credit

Allow the user to optionally upload a photos with each post.