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);*/

?>

Wednesday, 13 November 2019

Complete Prediction code

Hi All
Follow these four steps
DB Name :predictdb
Table Name  : predictdata



CREATE TABLE IF NOT EXISTS `predictdata` (
  `pid` int(11) NOT NULL,
  `temperature` text NOT NULL,
  `pressure` text NOT NULL,
  `sugar` text NOT NULL,
  `totalcount` text NOT NULL,
  `inputstring` text NOT NULL,
  `predictionresult` text NOT NULL
)


1. Input form and DB save with input string generation
----------------------------------------------------------------------------------------------------------

<html>
<body>
<form method=post >
<pre>
Patient Id  <input name=pid>
Temperature <select name=temperature>
            <option value='vhigh'>Very High</option>
            <option value='high'>High</option>
            <option value='medium'>Medium</option>
            <option value='low'>Low</option>
            <option value='vlow'>Very Low</option>
            </select>
Pressure <select name=pressure>
            <option value='vhigh'>Very High</option>
            <option value='high'>High</option>
            <option value='medium'>Medium</option>
            <option value='low'>Low</option>
            <option value='vlow'>Very Low</option>
            </select>
Sugar    <select name=sugar>
            <option value='vhigh'>Very High</option>
            <option value='high'>High</option>
            <option value='medium'>Medium</option>
            <option value='low'>Low</option>
            <option value='vlow'>Very Low</option>
            </select>
Totalcount <input name=count>
<input type=submit name='btnsave' value='Save'>
</form>
<?php

$con=mysql_connect("localhost","root","");
mysql_select_db("predictdb",$con);

if(isset($_POST['btnsave']))
{
$totalcount='';
if($_POST['count']<=100)
$totalcount='low';
else
$totalcount='high';
$inputstring="t_".$_POST['temperature']." p_".$_POST['pressure']." s_".$_POST['sugar']." tc_".$totalcount;
$qr="insert into predictdata values('$_POST[pid]','$_POST[temperature]','$_POST[pressure]','$_POST[sugar]','$totalcount','$inputstring','')";
echo $qr;
mysql_query($qr,$con);

}


?>

</body>
</html>


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

2. Download testdata.csv
----------------------------------------------------------------------------------------------------------


<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("predictdb",$con);
header('Content-Type: text/csv; charset=utf-8');
      header('Content-Disposition: attachment; filename=da.csv');
       $output = fopen("php://output", "w");
     fputcsv($output, array('pid','inputstring'));
         $query = "select *  from predictdata";
         $result = mysql_query($query, $con);
         while($row = mysql_fetch_array($result))
         {
              fputcsv($output,array($row['pid'],$row['inputstring']));
             
         }
      fclose($output);

?>
----------------------------------------------------------------------------------------------------------


3. Predict using python
----------------------------------------------------------------------------------------------------------
from nltk import NaiveBayesClassifier as nbc
from nltk.tokenize import word_tokenize
from itertools import chain
import csv

with open('trainingdata.csv','r'as csvinput:
    reader=csv.reader(csvinput,delimiter=",")
    rownum = 0 
    training_data = []

    for row in reader:
        training_data.append (row)
        rownum += 1

vocabulary = set(chain(*[word_tokenize(i[0].lower()) for i in training_data]))

feature_set = [({i:(i in word_tokenize(sentence.lower())) for i in vocabulary},tag) for sentence, tag in training_data]

classifier = nbc.train(feature_set)

with open('testdata.csv','r'as csvinput:
    with open('data.csv''w'as csvoutput:
        writer = csv.writer(csvoutput, lineterminator='\n')
        reader1 = csv.reader(csvinput)

        all = []
        row = next(reader1)
        

        for row in reader1:
            test_sentence = row[1]
            featurized_test_sentence =  {i:(i in word_tokenize(test_sentence.lower())) for i in vocabulary}
            print ("test_sent:",test_sentence)
            print ("tag:",classifier.classify(featurized_test_sentence))
            row.append(classifier.classify(featurized_test_sentence))
            all.append(row)
        writer.writerows(all)


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


4. Upload result to web using data.csv
----------------------------------------------------------------------------------------------------------
<form method='POST' enctype='multipart/form-data'>
<center>
Upload CSV FILE: <input type='file' name='csv_info' />
<input type='submit' name='submit' value='Upload' style="height: 50px; width: 150px; left: 250; top: 250;"/>
</center>
</form>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("predictdb",$con);
if(isset($_POST['submit'])){
if($_FILES['csv_info']['name']){
  $arrFileName = explode('.',$_FILES['csv_info']['name']);
   if($arrFileName[1] == 'csv'){
     $handle = fopen($_FILES['csv_info']['tmp_name'], "r");
      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
         $id=$data[0];
         $result = $data[2];
     
         $sql="update predictdata set predictionresult='$result' where pid='$id'";
mysql_query($sql);
                                   }
                        fclose($handle);
}
}
}
?>


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

Tuesday, 15 October 2019

PHP Code to upload csv file into a MySQL table

Hi All,
Use this code

Create a database SNITDB and table import(tid,name,tweet,label) to run this program.
----------------------------------------------------------------------------------
<form method='POST' enctype='multipart/form-data'>
<center>
Upload CSV FILE: <input type='file' name='csv_info' />
<input type='submit' name='submit' value='Upload' style="height: 50px; width: 150px; left: 250; top: 250;"/>
</center>
</form>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("SNITDB",$con);
if(isset($_POST['submit'])){
if($_FILES['csv_info']['name']){
$arrFileName = explode('.',$_FILES['csv_info']['name']);
if($arrFileName[1] == 'csv'){
$handle = fopen($_FILES['csv_info']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$item1 = mysqli_real_escape_string($con,$data[0]);
$item2 = mysqli_real_escape_string($con,$data[1]);
$item3= mysqli_real_escape_string($con,$data[2]);
$item4= mysqli_real_escape_string($con,$data[3]);
$sql="INSERT into import(tid,name,tweet,label) values('$item1','$item2','$item3','$item4')";
                                    mysqli_query($con,$sql);
                                   }
                        fclose($handle);
}
}
}
?>

PHP code to create CSV file from MySQL table

Hi All,
Use this code..
For this program to run create database SNITDB  and create a table tweet(tid,sname,tweet)
----------------------------------------------------------
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("SNITDB",$con);
header('Content-Type: text/csv; charset=utf-8');
      header('Content-Disposition: attachment; filename=da.csv');
       $output = fopen("php://output", "w");
    fputcsv($output, array('tid','sname', 'tweet'));
        $query = "select distinct * from tweet where label=0";
        $result = mysql_query($query, $con);
        while($row = mysql_fetch_array($result))
        {
             fputcsv($output,array($row['tid'],$row['sname'],$row['tweet']));
             $sql="update tweet set label=1 where tid='$row[tid]'";
             mysql_query($sql, $con);
        }
      fclose($output);

?>

Monday, 14 October 2019

Load Combo Box from DB

Hi All,

Use this code
Here the function showoptions takes table name as first argument, id as second argument and value to be displayed in the screen as third argument.
------------------------------------------------------------------------------------------------------
Showdata.php

<html>
<body>

<?php
include('dbconnect.php');
?>

<form  action=# method=post>
<pre>
Project Name <input>
Project Members <select name=projmembers multiple> <?php showoptions("reg_st","id","name"); ?></select>


</pre>
</form>
</body>
</html>


-------------------------------------------------------------------------------------
dbconnect.php

<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("snitdb",$con);

function showoptions($table,$value,$display)
{
$qr="select  * from  $table ";
echo $qr;

$data=mysql_query($qr);
while($row=mysql_fetch_array($data))
{
echo "<option value='".$row[$value]."'>".$row[$display]."</option>";

}

}


?>

Friday, 20 September 2019

Approval files

Hi all,

See the files associated with approval.


-------------------------------------
adminhome.php

<html>
<body>
<a href='approvestudent.php'>Approve student</a><br>
<a href='approvefaculty.php'>Approve faculty</a><br>
</body>
</html>

------------------------------------
approvestudent.php
----------------------------------
<?php
include('dbconnect.php');

$query = "select * from login where type='student' and

status='0'";
$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>Approve</th><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;
if($y==1)
    $c_row="****";
   echo '<td>' . $c_row . '</td>';
   next($row);
   $y = $y + 1;
  }
  echo '<td><a href=approvestudent1.php?id='.

$idval.'>Approve</a></td><td><a href=deletestudent.php?id='.

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

?>
----------------------------------------
approvestudent1.php
--------------------
<?php
include('dbconnect.php');
$id=$_GET['id'];
$qr="update login set status='1' where username='$id'";
mysql_query($qr,$con);
header("location:approvestudent.php");



?>
--------------------------
deletestudent.php
---------------------
<?php
include('dbconnect.php');
$id=$_GET['id'];
$qr="delete from login where username='$id'";
mysql_query($qr,$con);
header("location:approvestudent.php");



?>

Monday, 16 September 2019

PHP Upload Auto Num Validation Display Image

Hi All,
Use this code
-------------------------------------
Table SQL

CREATE TABLE IF NOT EXISTS `login` (
  `username` text NOT NULL,
  `password` text NOT NULL,
  `type` text NOT NULL,
  `status` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `studentreg` (
  `sid` int(11) NOT NULL,
  `name` text NOT NULL,
  `address` text NOT NULL,
  `email` text NOT NULL,
  `phone` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--------------------------------------------------------
dbconnect.php

<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("snit",$con);

?>

------------------------------------------------
studentform.php
-----------------------------------------------------
<html>
<body>
<?php
include('dbconnect.php');

//Code to insert into both registration and Login table
if(isset($_POST['btnsubmit']))
{
$sql="insert into studentreg values('$_POST[id1]','$_POST

[name]','$_POST[address]','$_POST[email]','$_POST

[phone]')";
echo $sql;
$sql1="insert into login values('$_POST[id1]','$_POST[password]','student','0')";
mysql_query($sql,$con);
mysql_query($sql1,$con);

$target_dir = "uploads/";
$target_file=$target_dir .$_POST['id1'].'.jpg';
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],

$target_file) or die('Error'.mysql_error());


}

?>

<?php

//Auto generate next id in the screen.

//Query to get the highest value in table

$sql="select max(sid) as mid from studentreg";
$data=mysql_query($sql);
$id=0;
while($row=mysql_fetch_array($data))
{
$id=$row['mid'];
}

$id=$id+1;
echo $id;
?>
<form action=# method=post  enctype="multipart/form-data">
<pre>
Id      <input name=id disabled=disabled value="<?php echo

$id ; ?>" pattern="[a-zA-Z]{2,10}" title="Enter only

characters">
<input type=hidden name=id1 value="<?php echo $id ; ?>" >
Name    <input name=name required=required maxlength=18>
Address <input name=address>
Email   <input type=email name=email>
Phone   <input name=phone pattern="[0-9]{10,12}">
Password<input name=password >
Photo   <input type="file" name="fileToUpload"

id="fileToUpload">
<input type=submit name=btnsubmit value='Save'>
</pre>
</form>

<?php

//Showing image in the table

$query = 'select * from studentreg';
$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);

?>
</body>
</html>



Thursday, 8 August 2019

View Table

Hi

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

$query = 'select * from tbl_Complaint';
$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><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);

?>