Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中固定的元素位置_Php_Html_Css - Fatal编程技术网

PHP中固定的元素位置

PHP中固定的元素位置,php,html,css,Php,Html,Css,我创建了一个星级评定系统。第一个函数在数据库中插入数据,第二个函数显示弹出窗口并从评论区域提取单词,然后设置特定的评级,第三个函数取数据库中所有评级存储的平均值。我的问题是,当我调用平均函数时,评级星自动向下移动。请帮助我在下面的代码中找到我的错误或编码弱点。如果有人能帮我,我会很感激的 <!Doctype html> <html> <head> <title>comments systems</tit

我创建了一个星级评定系统。第一个函数在数据库中插入数据,第二个函数显示弹出窗口并从评论区域提取单词,然后设置特定的评级,第三个函数取数据库中所有评级存储的平均值。我的问题是,当我调用平均函数时,评级星自动向下移动。请帮助我在下面的代码中找到我的错误或编码弱点。如果有人能帮我,我会很感激的

<!Doctype html>
    <html>
        <head>
        <title>comments systems</title>
        </head>
        <body>
        <h1 >this is comments system</h1>
            <?php
             include 'comments1.php';       
              echo"<form  method='post' action='".set()."'> 
            <label>Email</label>
            <input type='email' name='email' placeholder='Your mail..' required >
            <br>
            <label for='subject'>Subject</label>
            <textarea  name='mess' placeholder='this is text' rows='5' cols='50' required></textarea>
            <input type='submit' name='Submit'> 

            </form>";

            get();//message and mail taking
            rating();
           // echo 
         $rating=average();
         $resrat=round($rating);
             echo"<div style='margin-left: 115px; margin-top: 2370px;'>";
            echo"---";
        for($i=1; $i<=$resrat; $i++) // simple for loop
        { 
          echo '<img src="Star (Full).png" width="100"/>'; 
        }

        echo"</div>";

            ?>
        </body>
    </html>

评论系统
这是评论系统
//第二档

<?php
session_start();
function set()
{
    $Mail = isset($_POST['email']) ? $_POST['email'] : '';
    $MESS=isset($_POST['mess']) ? $_POST['mess'] : '';
$conn=mysqli_connect('localhost','root');
mysqli_select_db($conn,'reg');
    if(!empty($Mail && $MESS))
    {   
$sql="INSERT INTO  Persons (email,message,curdate)VALUES ('$Mail', '$MESS',now())";//ID is auto increment due to this not mention. 
if(mysqli_query($conn,$sql))
    {
//echo "data submited";Nothing do here
    }
else {
//echo "data not submited";
  echo "<link rel='stylesheet' type='text/css' href='sweet-alert.css''>";
   echo  "<script src='sweet-alert.js'></script>";
   echo '<script type="text/javascript">';
  echo 'setTimeout(function () {swal("Data Not Submited!");';
  echo '}, );</script>';
     }

    }
            }

 function get(){ 
$con=mysqli_connect('localhost','root');
mysqli_select_db($con,'reg');
    $page=$_GET["page"];  //this page is that link where we click on
    if($page==" "||$page=="1")
        {
           $pageget=0; 
        } 
     else
        {
        $pageget= ($page*5)-5;  
        }

if($con)
{
    $sql="SELECT * FROM Persons  LIMIT $pageget, 5";
    $res=mysqli_query($con,$sql);
    while($row=mysqli_fetch_array($res))
    {
     echo  date("Y/m/d");
     echo "<br>";
     echo $row['message'];
     echo "<br>";
     echo "<hr>";
    }

    $sql="SELECT * FROM Persons";
    $res1=mysqli_query($con,$sql) or die(mysqli_error($con));
    $cnt=mysqli_num_rows($res1);//cnt=counting
    echo "<br>";
    $totalpages=floor($cnt/5);
    //echo $totalpages;
    $current_page = isset($_GET['page']) ? $_GET['page'] : 1;
    if( $current_page > 1 ) 
    {
        $prev = '<a href="comments.php?page='.($current_page-1).'"><div style="border-style: groove; float:left " >Previous</div></a>';
        echo $prev;
    }

    for($page=1;$page<=$totalpages;$page++) 
    {
        ?>
        <a href="comments.php?page=<?php echo $page." ";?>" style="text-decoration:none text-align:center;"><?php echo '<div style="border-style: groove; width:25px;float:left" >'. $page." ".'</div>'; ?></a><?php
    }

    if( $current_page < $totalpages ) 
    {
        $next = '<a href="comments.php?page='.($current_page+1).'"><div style="border-style: groove;float:left" >Next</div></a>';
        echo $next;
    }

     }
 }

function rating()
{
    $Mail=isset($_POST['email']) ? $_POST['email'] : '';
    $MESS=isset($_POST['mess']) ? $_POST['mess'] : '';
    $conn=mysqli_connect('localhost','root');
    mysqli_select_db($conn,'reg');
 //if(empty($Mail && $MESS)){echo "sorry";}
    if(!empty($Mail && $MESS))
 //else
    {
    echo "<br>";
   $Email=$Mail;
  // echo $Email;
    $string=$MESS;
 //FIRST
    if (strpos($string, 'VERY GOOD') ||strpos($string, 'very good')||strpos($string, 'spacious')||strpos($string, 'Bravo') ||strpos($string, 'Very Good')||strpos($string, 'bravo')!== false)
    {
    //echo  '3';
     //  echo
        $rating=4;
$sql="UPDATE Persons SET Rating=$rating WHERE email='$Email';"; // if remove this '' from varible'$Email' it not work becacuse it was string.
if(mysqli_query($conn,$sql))
  {
   //echo "yes added rating";
  echo "<link rel='stylesheet' type='text/css' href='sweet-alert.css''>";
   echo  "<script src='sweet-alert.js'></script>";
   echo '<script type="text/javascript">';
  echo 'setTimeout(function () {swal("Your Feedback Considered = 4 Star!");';
  echo '}, );</script>';
  }
else
{
  // echo " not rating added".error;
    echo "<link rel='stylesheet' type='text/css' href='sweet-alert.css''>";
   echo  "<script src='sweet-alert.js'></script>";
   echo '<script type="text/javascript">';
  echo 'setTimeout(function () {swal("Your Feedback Not Considerd!");';
  echo '}, );</script>'.error;
}

  }
 //SECOND
 else if(strpos($string, 'GOOD') ||strpos($string, 'good')||strpos($string, 'not bad')||strpos($string, 'Not Bad')!== false) 
 {
    // echo "your feed back has no our required words! at least one is required";
       //echo 
     $rating=3;
$sql="UPDATE Persons SET Rating=$rating WHERE email='$Email';"; // if remove this '' from varible'$Email' it not work becacuse it was string.
if(mysqli_query($conn,$sql))
   {
   echo "<link rel='stylesheet' type='text/css' href='sweet-alert.css''>";
   echo  "<script src='sweet-alert.js'></script>";
   echo '<script type="text/javascript">';
  echo 'setTimeout(function () {swal("Your Feedback Considered = 3 Star!");';
  echo '}, );</script>';
   }
else 
  {
  echo "<link rel='stylesheet' type='text/css' href='sweet-alert.css''>";
   echo  "<script src='sweet-alert.js'></script>";
   echo '<script type="text/javascript">';
  echo 'setTimeout(function () {swal("Your Feedback Not Considerd!");';
  echo '}, );</script>'.error;
   }

 }
 //THIRD
 else if(strpos($string, 'Bad') ||strpos($string, 'bad')||strpos($string, 'BAD')!== false)
 {
    // echo "your feed back has no our required words! at least one is required";
       //echo 
     $rating=2;
$sql="UPDATE Persons SET Rating=$rating WHERE email='$Email';"; // if remove this '' from varible'$Email' it not work becacuse it was string.
if(mysqli_query($conn,$sql))
  {
    echo "<link rel='stylesheet' type='text/css' href='sweet-alert.css''>";
   echo  "<script src='sweet-alert.js'></script>";
   echo '<script type="text/javascript">';
  echo 'setTimeout(function () {swal("Your Feedback Considered = 2 Star!");';
  echo '}, );</script>';
  }
else 
   {
    echo "<link rel='stylesheet' type='text/css' href='sweet-alert.css''>";
   echo  "<script src='sweet-alert.js'></script>";
   echo '<script type="text/javascript">';
  echo 'setTimeout(function () {swal("Your Feedback Not Considerd!");';
  echo '}, );</script>'.error;
   }
 }
 //FORTH
  else if(strpos($string, 'very bad') ||strpos($string, 'VERY BAD')||strpos($string, 'so bad')||strpos($string, 'Very Bad')||strpos($string, 'So Bad')!== false) {
    // echo "your feed back has no our required words! at least one is required";
       //echo 
      $rating=1;
$sql="UPDATE Persons SET Rating=$rating WHERE email='$Email';"; // if remove this '' from varible'$Email' it not work becacuse it was string.
if(mysqli_query($conn,$sql))
{
echo "<link rel='stylesheet' type='text/css' href='sweet-alert.css''>";
   echo  "<script src='sweet-alert.js'></script>";
   echo '<script type="text/javascript">';
  echo 'setTimeout(function () {swal("Your Feedback Considered = 1 Star!");';
  echo '}, );</script>';
}
else {
      echo "<link rel='stylesheet' type='text/css' href='sweet-alert.css''>";
   echo  "<script src='sweet-alert.js'></script>";
   echo '<script type="text/javascript">';
  echo 'setTimeout(function () {swal("Your Feedback Not Considerd!");';
  echo '}, );</script>'.error;
     }
 }

//FIFTH
  else if(strpos($string, 'excellent') ||strpos($string, 'EXCELLENT')||strpos($string, 'Perfect')||strpos($string, 'Excellent')||strpos($string, 'perfect')!== false) {
    // echo "your feed back has no our required words! at least one is required";
       //echo
      $rating=5;
$sql="UPDATE Persons SET Rating=$rating WHERE email='$Email';"; // if remove this '' from varible'$Email' it not work becacuse it was string.
if(mysqli_query($conn,$sql))
{
echo "<link rel='stylesheet' type='text/css' href='sweet-alert.css''>";
   echo  "<script src='sweet-alert.js'></script>";
   echo '<script type="text/javascript">';
  echo 'setTimeout(function () {swal("Your Feedback Considered = 5 Star!");';
  echo '}, );</script>';
}
else {
     echo "<link rel='stylesheet' type='text/css' href='sweet-alert.css''>";
   echo  "<script src='sweet-alert.js'></script>";
   echo '<script type="text/javascript">';
  echo 'setTimeout(function () {swal("Your Feedback Not Considerd!");';
  echo '}, );</script>'.error;
    }
 }
 //6th
  else if(strpos($string, 'excellent') ||strpos($string, 'good')||strpos($string, 'Perfect')||strpos($string, 'bad')||strpos($string, 'perfect')!== true) {
       echo  $rating=1;
$sql="UPDATE Persons SET Rating=$rating WHERE email='$Email';"; // if remove this '' from varible'$Email' it not work becacuse it was string.
if(mysqli_query($conn,$sql))
{
echo "Rating Considered as low, Please use relevent words";
}

 }
 }

}
function average()
{
     //average calculate
  $con=mysqli_connect('localhost','root');
     mysqli_select_db($con,'reg');
      $sql="SELECT * FROM Persons";
     $res1=mysqli_query($con,$sql);
 $avg=0;
 $count=0;
  while($row=mysqli_fetch_array($res1))
    {
      echo "<br>";
       $count+=1;
      // echo $count
          $avg+=$row['Rating'];
        $result=$avg/$count;
    }
    return $result;

}
?>

如果要在php中计算平均值,请更改:

$total=0;
$avg=0;
$count=0;

while($row=mysqli_fetch_array($res1))
   {
     echo "<br>";
     $count+=1;
     $avg+=$row['Rating'];
     $result=$avg/$count;
   }
您还可以通过使用mysql
AVG()
函数和一个查询直接计算平均值

您的代码易受SQL注入攻击,即使改用,也会受到黑客攻击。我是这个论坛的新手。不要这样做。我不知道你的意思。“下移”是什么意思?@YaakovAinspan,评级星的位置会自动下降。我不想计算平均值。我的问题是,当我在comments.php文件中调用此函数时,评级星会自动向下移动。我想把这个星星的柱子修好@Sebastien SYour函数似乎错误地计算了平均。。。如果您只是想解决调用此函数时图形位置下降的问题,可能是因为
echo“
while
循环中执行code>。然后删除这一行。我的函数计算平均值100%为真。我有很多时间来测试它。请关注我的问题,而不是一般的问题。我告诉过你你的问题。。。移除回声“
,位置不会下降。只有当你只有一个结果时,你的另一手平均法才有效。在这种情况下,您不需要
while
循环。谢谢亲爱的@Sebastien S。我发现了我的错误。在你们的帮助下。你们是很棒的人。。
$totalRate = 0;
$totalRows = $res1->num_rows;

while($row=mysqli_fetch_array($res1))
   $totalRate += $row['Rating'];

$avg = $totalRate / $totalRows;