Initial commit
This commit is contained in:
74
lieder/star/DBController.php
Normal file
74
lieder/star/DBController.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
class DBController
|
||||
{
|
||||
|
||||
private $host = "localhost";
|
||||
|
||||
private $user = "root";
|
||||
|
||||
private $password = "";
|
||||
|
||||
private $database = "leitgedanken";
|
||||
|
||||
private static $conn;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->conn = mysqli_connect($this->host, $this->user, $this->password, $this->database);
|
||||
}
|
||||
|
||||
public static function getConnection()
|
||||
{
|
||||
if (empty($this->conn)) {
|
||||
new Database();
|
||||
}
|
||||
}
|
||||
|
||||
function getDBResult($query, $params = array())
|
||||
{
|
||||
$sql_statement = $this->conn->prepare($query);
|
||||
if (! empty($params)) {
|
||||
$this->bindParams($sql_statement, $params);
|
||||
}
|
||||
$sql_statement->execute();
|
||||
$result = $sql_statement->get_result();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$resultset[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($resultset)) {
|
||||
return $resultset;
|
||||
}
|
||||
}
|
||||
|
||||
function updateDB($query, $params = array())
|
||||
{
|
||||
$sql_statement = $this->conn->prepare($query);
|
||||
if (! empty($params)) {
|
||||
$this->bindParams($sql_statement, $params);
|
||||
}
|
||||
$sql_statement->execute();
|
||||
}
|
||||
|
||||
function bindParams($sql_statement, $params)
|
||||
{
|
||||
$param_type = "";
|
||||
foreach ($params as $query_param) {
|
||||
$param_type .= $query_param["param_type"];
|
||||
}
|
||||
|
||||
$bind_params[] = & $param_type;
|
||||
foreach ($params as $k => $query_param) {
|
||||
$bind_params[] = & $params[$k]["param_value"];
|
||||
}
|
||||
|
||||
call_user_func_array(array(
|
||||
$sql_statement,
|
||||
'bind_param'
|
||||
), $bind_params);
|
||||
}
|
||||
}
|
32
lieder/star/Rate.php
Normal file
32
lieder/star/Rate.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
require_once "DBController.php";
|
||||
|
||||
class Rate extends DBController
|
||||
{
|
||||
|
||||
function getAllPost($id)
|
||||
{
|
||||
$query = "SELECT laid id, rating FROM lieder_auffuehrung WHERE laid=$id";
|
||||
$postResult = $this->getDBResult($query);
|
||||
return $postResult;
|
||||
}
|
||||
|
||||
|
||||
function updateRatingCount($rating, $id)
|
||||
{
|
||||
$query = "UPDATE lieder_auffuehrung SET rating = ? WHERE laid= ?";
|
||||
|
||||
$params = array(
|
||||
array(
|
||||
"param_type" => "i",
|
||||
"param_value" => $rating
|
||||
),
|
||||
array(
|
||||
"param_type" => "i",
|
||||
"param_value" => $id
|
||||
)
|
||||
);
|
||||
|
||||
$this->updateDB($query, $params);
|
||||
}
|
||||
}
|
7
lieder/star/add_rating.php
Normal file
7
lieder/star/add_rating.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
if(!empty($_POST["rating"]) && !empty($_POST["id"])) {
|
||||
require_once("Rate.php");
|
||||
$rate = new Rate();
|
||||
$rate->updateRatingCount($_POST["rating"], $_POST["id"]);
|
||||
}
|
||||
?>
|
98
lieder/star/index.php
Normal file
98
lieder/star/index.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
require_once("Rate.php");
|
||||
$rate = new Rate();
|
||||
$result = $rate->getAllPost("1");
|
||||
|
||||
?>
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>PHP Dynamic Star Rating using jQuery</TITLE>
|
||||
<style>
|
||||
body{width:610;}
|
||||
.rating-table {width: 100%;border-spacing: initial;margin: 20px 0px;word-break: break-word;table-layout: auto;line-height:1.8em;color:#333;}
|
||||
.rating-table th {background: #999;padding: 5px;text-align: left;color:#FFF;}
|
||||
.rating-table td {border-bottom: #f0f0f0 1px solid;background-color: #ffffff;padding: 5px;}
|
||||
.rating-table td div.feed_title{text-decoration: none;color:#00d4ff;font-weight:bold;}
|
||||
.rating-table ul{margin:0;padding:0;}
|
||||
.rating-table li{cursor:pointer;list-style-type: none;display: inline-block;color: #F0F0F0;text-shadow: 0 0 1px #666666;font-size:20px;}
|
||||
.rating-table .highlight, .rating-table .selected {color:#F4B30A;text-shadow: 0 0 1px #F48F0A;}
|
||||
</style>
|
||||
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
|
||||
<script>function highlightStar(obj,id) {
|
||||
removeHighlight(id);
|
||||
$('.rating-table #tutorial-'+id+' li').each(function(index) {
|
||||
$(this).addClass('highlight');
|
||||
if(index == $('.rating-table #tutorial-'+id+' li').index(obj)) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function removeHighlight(id) {
|
||||
$('.rating-table #tutorial-'+id+' li').removeClass('selected');
|
||||
$('.rating-table #tutorial-'+id+' li').removeClass('highlight');
|
||||
}
|
||||
|
||||
function addRating(obj,id) {
|
||||
$('.rating-table #tutorial-'+id+' li').each(function(index) {
|
||||
$(this).addClass('selected');
|
||||
$('#tutorial-'+id+' #rating').val((index+1));
|
||||
if(index == $('.rating-table #tutorial-'+id+' li').index(obj)) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
url: "add_rating.php",
|
||||
data:'id='+id+'&rating='+$('#tutorial-'+id+' #rating').val(),
|
||||
type: "POST"
|
||||
});
|
||||
}
|
||||
|
||||
function resetRating(id) {
|
||||
if($('#tutorial-'+id+' #rating').val() != 0) {
|
||||
$('.rating-table #tutorial-'+id+' li').each(function(index) {
|
||||
$(this).addClass('selected');
|
||||
if((index+1) == $('#tutorial-'+id+' #rating').val()) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
} </script>
|
||||
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<table class="rating-table">
|
||||
<tbody>
|
||||
<?php
|
||||
if(!empty($result)) {
|
||||
$i=0;
|
||||
foreach ($result as $tutorial) {
|
||||
?>
|
||||
<tr>
|
||||
<td valign="top">
|
||||
|
||||
<div id="tutorial-<?php echo $tutorial["id"]; ?>">
|
||||
<input type="hidden" name="rating" id="rating" value="<?php echo $tutorial["rating"]; ?>" />
|
||||
<ul onMouseOut="resetRating(<?php echo $tutorial["id"]; ?>);">
|
||||
<?php
|
||||
for($i=1;$i<=10;$i++) {
|
||||
$selected = "";
|
||||
if(!empty($tutorial["rating"]) && $i<=$tutorial["rating"]) {
|
||||
$selected = "selected";
|
||||
}
|
||||
?>
|
||||
<li class='<?php echo $selected; ?>' onmouseover="highlightStar(this,<?php echo $tutorial["id"]; ?>);" onmouseout="removeHighlight(<?php echo $tutorial["id"]; ?>);" onClick="addRating(this,<?php echo $tutorial["id"]; ?>);">★</li>
|
||||
<?php } ?>
|
||||
<ul>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</BODY>
|
||||
</HTML>
|
4
lieder/star/jquery-2.1.1.min.js
vendored
Normal file
4
lieder/star/jquery-2.1.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
12
lieder/star/tutorial.sql
Normal file
12
lieder/star/tutorial.sql
Normal file
@ -0,0 +1,12 @@
|
||||
CREATE TABLE IF NOT EXISTS `tutorial` (
|
||||
`id` int(8) NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`description` text NOT NULL,
|
||||
`rating` tinyint(2) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
)
|
||||
|
||||
INSERT INTO `tutorial` (`id`, `title`, `description`, `rating`) VALUES
|
||||
(1, 'Favorite Star Rating with jQuery', 'This tutorial is for doing favorite star rating using jQuery. It displays list of HTML stars by using li tags. These stars are highlighted by using CSS and jQuery based on the favorite rating selected by the user.', 1),
|
||||
(2, 'PHP RSS Feed Read and List', 'PHP''s simplexml_load_file() function is used for reading data from xml file. Using this function, we can parse RSS feed to get item object array.', 3),
|
||||
(3, 'jQuery AJAX Autocomplete – Country Example', 'Autocomplete feature is used to provide auto suggestion for users while entering input. It suggests country names for the users based on the keyword they entered into the input field by using jQuery AJAX.', 5);
|
Reference in New Issue
Block a user