Jump to content
xisto Community
Sign in to follow this  
Prophet.K

Review & Score Editor.

Recommended Posts

Okay so ever wanted to right a review on your website, and other people review it if its a good review or not? Well, now you can.

-- This is a stand alone example of a review system. This is the administration page for entering and editing reviews. It'll create your table for you automatically, so all you need to do is change the database settings. You may extract the database code and put it into a file called db.php. You can also extract the get_reviews() function and put it into a file called reviews.php. Just make sure you include() both files for this to work. This does not support front end displaying, but it can easily be modified to do so if you split the files up. Give it a try as-is on your local or hosted PHP account.

<?php/********************************************************************************/// DB connection and table.  This can be moved to a separate file. If you do that// You'll need to add this line://// include('db.php'); ///* db.php */$mysql_server = 'localhost';$mysql_user = 'root';$mysql_pass = '';$mysql_db = 'test';$dbcon = mysql_connect($mysql_server, $mysql_user, $mysql_pass);if(!$dbcon){   print 'Could not connect to mysql';   exit;}if(!mysql_select_db($mysql_db, $dbcon)){   print 'Could not select database';   exit;}$query = "CREATE TABLE IF NOT EXISTS `reviews` (  `review_id` int(11) NOT NULL auto_increment,  `datetime` datetime NOT NULL default '0000-00-00 00:00:00',  `timestamp` timestamp(14) NOT NULL,  `review_title` varchar(250) NOT NULL default '',  `review_body` text NOT NULL,  `review_score` int(11) NOT NULL default '0',  PRIMARY KEY  (`review_id`),  KEY `review_id` (`review_id`),  FULLTEXT KEY `review` (`review_title`,`review_body`)) TYPE=MyISAM AUTO_INCREMENT=1;";mysql_query($query);/* db.php end *//********************************************************************************/// Gets a review from the db based on it's review_id// This function should be put into it's own file called reviews.php//// include('reviews.php');//function get_reviews($review_id = '0'){	global $dbcon;	if($review_id)	{		$where = "where review_id = '$review_id'";	}	$query = "		select			*		from 			reviews		$where			order by			datetime desc	"; 	$result = mysql_query($query, $dbcon);	$rows = mysql_num_rows($result);	$reviews = array();	if($rows > 0)	{		while($row = mysql_fetch_assoc($result))		{			if($review_id)			{						return $row;			}				else			{				$reviews[$row[review_id]] = $row;			}		}		}	return $reviews;}/********************************************************************************/// Collect variables from the URL and POST variables	$review_id = $_POST[review_id];if(!$review_id) {	$review_id = $_GET[review_id];}$op = $_POST[op];/********************************************************************************/// Saving the new or edited review to the database.switch($op){	case 'save':		$review_title = addslashes(stripslashes($_POST[review_title]));		$review_score = addslashes(stripslashes($_POST[review_score]));		$review_body = addslashes(stripslashes($_POST[review_body]));		$set = "			timestamp = now(),			review_title = "$review_title",			review_score = "$review_score",			review_body = "$review_body"		";			if($review_id)		{			$query = "update reviews set $set where review_id = '$review_id'";		}		else		{			$query = "insert into reviews set datetime = now(), $set";		}		mysql_query($query);}/********************************************************************************/// Include or print your header here?><html><head><title>Article Editor</title><style type="text/css"><!--td, body { font-family: Arial; font-size: 14px; color: #000000; text-decoration: none; font-weight: none}.white { font-family: Arial; font-size: 14px; color: #FFFFFF; text-decoration: none; font-weight: bold}a.header:link {  font-family: Verdana, Arial, Helvetica, Sans-serif; font-size: 13px; color: #FFFFFF; text-decoration: none; font-weight: bold}a.header:visited {  font-family: Verdana, Arial, Helvetica, Sans-serif; font-size: 13px; color: #FFFFFF; text-decoration: none; font-weight: bolder}a.header:hover {  font-family: Verdana, Arial, Helvetica, Sans-serif; font-size: 13px; color: #FFFFFF; text-decoration: underline; font-weight: bolder}a:link {  font-family: Verdana, Arial, Helvetica, Sans-serif; font-size: 13px; color: #000088; text-decoration: none; font-weight: bolder}a:visited {  font-family: Verdana, Arial, Helvetica, Sans-serif; font-size: 13px; color: #000088; text-decoration: none; font-weight: bolder}a:hover {  font-family: Verdana, Arial, Helvetica, Sans-serif; font-size: 13px; color: #000000; text-decoration: none; font-weight: bolder}--></style></head><body bgcolor="#FFFFFF"><h3><a href='?'>Write new Review</a></h3><?php/********************************************************************************/// If we have a review_id, only show that particular review and it's edit form.// If there is no specific review_id, show all of the reviews.$reviews = get_reviews();if(count($reviews) > 0){	foreach($reviews as $r_id => $review)	{		$review_title = htmlentities($review[review_title], ENT_QUOTES);		$review_score = $review[review_score];		$review_body = $review[review_body];		$datetime = $review[datetime];		list($date, $time) = split(" ", $datetime);		list($year, $month, $day) = split("-", $date);		$date = date('M d, Y', mktime(0, 0, 0, $month, $day, $year));?><table width=600 cellpadding=5 cellspacing=0 border=0><tr bgcolor="#FFFFFF">	<td align=left valign=top width=100><?php print $date; ?></td>	<td align=left valign=top><a href='<?php print "$_SELF?review_id=$r_id" ?>'><?php print $review_title; ?></a></td></tr>	</table><?php	}}	if($review_id){	$review = get_reviews($review_id);	$review_title = htmlentities($review[review_title], ENT_QUOTES);	$review_score = $review[review_score];	$review_body = $review[review_body];?><!-- This is the html you use to display a review --><br><br><table width=600 bgcolor='#000000' cellpadding=8 cellspacing=1 border=0><tr bgcolor="#FFFFFF">	<td align=left>	<b><?php print $date; ?></b><br>	<?php print $review_title; ?><br><br>	<?php print $review_body; ?><br><br>	</td></tr></table><?php}	else{	unset($review_title);	unset($review_score);	unset($review_body);}?><!-- This is the html you use to edit a review --><br><br><form method=post action='<?php print $_SELF; ?>'><input type='hidden' name='op' value='save'><input type='hidden' name='review_id' value='<?php print $review_id; ?>'><table width=600 cellpadding=0 cellspacing=1 bgcolor=#000000><tr>	<td align=left><table width=100% cellpadding=8 cellspacing=0 border=0>	<tr bgcolor="#FFFFFF">		<td align=right valign=top width=120>Review Score</td>		<td align=left valign=top><input type=text size=5 maxlength=25 name='review_score' value='<?php print $review_score; ?>'></td>	</tr>		<tr bgcolor="#FFFFFF">		<td align=right valign=top>Review Title</td>		<td align=left valign=top><input type=text size=30 maxlength=250 name='review_title' value='<?php print $review_title; ?>'></td>	</tr>		<tr bgcolor="#FFFFFF">		<td align=right valign=top>Review Body</td>		<td align=left valign=top><textarea cols=60 rows=15 name='review_body'><?php print $review_body; ?></textarea></td>	</tr>		<tr bgcolor="#FFFFFF">		<td align=right valign=top colspan=2><input type=submit name=submit value='Save'></td>	</tr>		</table></td></tr></table></form><?phpmysql_close($dbcon);?></HTML>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.