Friday, 27 December 2019

Star Rating in PHP

Hi All,

See the code
---------------------------------------------

CREATE TABLE IF NOT EXISTS `upload` (
  `vid` int(10) NOT NULL,
  `uid` int(10) NOT NULL,
  `videos` varchar(50) NOT NULL,
  `details` varchar(50) NOT NULL,
  `date` date NOT NULL,
  `points` int(11) NOT NULL,
  PRIMARY KEY (`vid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

----------------------------------------------
viewvideos.php

<?php
include('connect.php');

$query = 'select * from upload';
$result = mysql_query($query);
if (!$result)
{
$message = 'ERROR:' . mysql_error();
return $message;
}
else
{
$i = 0;
echo '<html><body><table border=1 align=center><tr>';
while ($i < mysql_num_fields($result))
{
$meta = mysql_fetch_field($result, $i);
echo '<th>' . ucfirst($meta->name) . '</th>';
$i = $i + 1;
}
echo '<th>View</th>';
  echo '';
  echo '</tr>';
$i = 0;
while ($row = mysql_fetch_row($result))
{
echo '<tr>';
$count = count($row);
$y = 0;
$idval='1';
while ($y < $count)
{
$c_row = current($row);
if($y==0)
$idval=$c_row;
echo '<td>' . $c_row . '</td>';
next($row);
$y = $y + 1;
}
echo '<td><a href=videoupload/'.$idval.'.mp4>View Video</a></td>';
    echo '<td><a href=rating.php?vid='.$idval.'&val=1><img width=30 height=30 src=images/star.jpg></a><a href=rating.php?vid='.$idval.'&val=2><img width=30 height=30 src=images/star.jpg></a><a href=rating.php?vid='.$idval.'&val=3><img width=30 height=30 src=images/star.jpg></a></td>';
echo '</tr>';
$i = $i + 1;
}
echo '</table></body></html>';
mysql_free_result($result);
}
mysql_close ($con);

?></center>

----------------------------------------------
rating.php
<?php
 include('connect.php');
 session_start();
 $id=$_GET['vid'];
 $val=$_GET['val'];
 $sql="update upload set points=points+".$val." where vid='$id'";
 echo $sql;
 mysql_query($sql,$con);
header('location:viewvideos.php')
?>

View data using PHP

HI All,

See the code

------------------------------------------------------------------------------

<?php
include('connect.php');

$query = 'select * from upload';
$result = mysql_query($query);
if (!$result)
{
$message = 'ERROR:' . mysql_error();
return $message;
}
else
{
$i = 0;
echo '<html><body><table border=1 align=center><tr>';
while ($i < mysql_num_fields($result))
{
$meta = mysql_fetch_field($result, $i);
echo '<th>' . ucfirst($meta->name) . '</th>';
$i = $i + 1;
}
echo '<th>View</th>';
  echo '<th>Rating</th></tr>';
$i = 0;
while ($row = mysql_fetch_row($result))
{
echo '<tr>';
$count = count($row);
$y = 0;
$idval='1';
while ($y < $count)
{
$c_row = current($row);
if($y==0)
$idval=$c_row;
echo '<td>' . $c_row . '</td>';
next($row);
$y = $y + 1;
}
echo '<td><a href=videoupload/'.$idval.'.mp4>View Video</a></td>';
    echo '<td><a href=rating.php><img src="images/star.jpg"></a></td>';
echo '</tr>';
$i = $i + 1;
}
echo '</table></body></html>';
mysql_free_result($result);
}
mysql_close ($con);

?></center>
<?php

//Showing image in the table
/*$query = 'select * from userreg';
$result = mysql_query($query);
if (!$result)
{
 $message = 'ERROR:' . mysql_error();
 return $message;
}
else
{
 $i = 0;
 echo '<html><body><table border=1 align=center><tr>';
 while ($i < mysql_num_fields($result))
 {
  $meta = mysql_fetch_field($result, $i);
  echo '<th>' . ucfirst($meta->name) . '</th>';
  $i = $i + 1;
 }
 echo '<th>Delete</th></tr>';
 $i = 0;
 while ($row = mysql_fetch_row($result))
 {
  echo '<tr>';
  $count = count($row);
  $y = 0;
  $idval='1';
  while ($y < $count)
  {
   $c_row = current($row);
   if($y==0)
    $idval=$c_row;
   echo '<td>' . $c_row . '</td>';
   next($row);
   $y = $y + 1;
  }
  echo "<td><img width=30 height=30 src='uploads/

$idval.jpg'></td><td><a href=delComplaint.php?id='.

$idval.'>Delete</a></td>";
  echo '</tr>';
  $i = $i + 1;
 }
 echo '</table></body></html>';
 mysql_free_result($result);
}
mysql_close ($con);*/

?>