Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.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/1/php/267.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
Javascript 速率图像系统_Javascript_Php_Jquery_Sql_Ajax - Fatal编程技术网

Javascript 速率图像系统

Javascript 速率图像系统,javascript,php,jquery,sql,ajax,Javascript,Php,Jquery,Sql,Ajax,因此,我创建了这个函数,您可以将一个图像和一些信息一起上传到服务器。 文本信息保存到数据库中,而图像保存到文件夹中。 然后我将图像与存储在数据库中的信息一起回显。 但我想通过增加一个评级系统来加强它 我创建的评级系统将统计数据存储在txt文件中。 我需要的帮助是用txt文件中的统计数据交换保存,并将其存储在数据库中 这就是我如何回显图像,以及信息和星号功能: <?php //Sortering $order = ""; if(isset($_GET['order'])){ if

因此,我创建了这个函数,您可以将一个图像和一些信息一起上传到服务器。 文本信息保存到数据库中,而图像保存到文件夹中。 然后我将图像与存储在数据库中的信息一起回显。 但我想通过增加一个评级系统来加强它

我创建的评级系统将统计数据存储在txt文件中。 我需要的帮助是用txt文件中的统计数据交换保存,并将其存储在数据库中

这就是我如何回显图像,以及信息和星号功能:

<?php
//Sortering

$order = "";
if(isset($_GET['order'])){

    if($_GET['order'] == "date"){
        $order = " ORDER BY date DESC";
    }
}
if(isset($_GET['order'])){
    if($_GET['order'] == "uppladdare"){
        $order = " ORDER BY uppladdare";
    }
}
//Database connection
$dbcon = mysqli_connect("");
$selectall = "SELECT * FROM mountains $order";
$result = mysqli_query($dbcon, $selectall);

while($row = mysqli_fetch_array($result)){

$information =  ' Titel: ' . $row['titel'] . ' Uppladdare: ' . $row['uppladdare'] . ' Filnamn: ' . $row['filname'] . ' History: ' .$row['History'] . ' Datum: ' . $row['date']; 

//Print out correct information to the uploaded image
echo "<br>";
echo "Title: " . $row['titel'] . "<br>";
echo "Uploader: " . $row['uppladdare'] . "<br>";
echo "Imagename: " . $row['filname'] . "<br>";
echo "History: " . $row['History'] . "<br>";
echo "Date: " . $row['date'] . "<br>";
echo "Image:";
echo "<br>";
echo "<form name='rating' id='rating'>    
    <div id='rating-area' class='shadow'>   

    <img src='stjärna.png' id='thumb1' data-value='1' />
    <img src='stjärna.png' id='thumb2' data-value='2' />
    <img src='stjärna.png' id='thumb3' data-value='3' />
    <img src='stjärna.png' id='thumb4' data-value='4' />
    <img src='stjärna.png' id='thumb5' data-value='5' />

    </div>


</form>";
?>
<script>
    jQuery('div#rating-area img').click(function(e){
        var val = jQuery(this).data('value') ;
        console.log(val) ;
        jQuery.post('post.php',{ rating : val },function(data,status){
            console.log('data:'+data+'/status'+status) ;
        }) ;
    }) ;

</script>
<script>
   $(document).ready(function(){
     setInterval(function(){
     $('#resultat').load('ajax.php');

       },500);

   });
 </script>
 <?php

$original = $row['filname'];

echo "<a class='fancybox' rel='massoravbilder' href='bilder/$original'> <img src='bilder/thumb_" . $row['filname'] . "' alt='$information' /></a>" . "<br>";

}

?>
<script>
    jQuery('div#rating-area img').click(function(e){
        var val = jQuery(this).data('value') ;
        console.log(val) ;
        jQuery.post('post.php',{ rating : val },function(data,status){
            console.log('data:'+data+'/status'+status) ;
        }) ;
    }) ;

</script>

您应该这样做。我不知道是否存在字段,但这是接下来的方法。我希望这能给你一个想法

以您的形式

//...
while($row = mysqli_fetch_array($result)){

    $information =  ' Titel: ' . $row['titel'] . ' Uppladdare: ' . $row['uppladdare'] . ' Filnamn: ' . $row['filname'] . ' History: ' .$row['History'] . ' Datum: ' . $row['date']; 

    //Print out correct information to the uploaded image
    echo "<br>";
    echo "Title: " . $row['titel'] . "<br>";
    echo "Uploader: " . $row['uppladdare'] . "<br>";
    echo "Imagename: " . $row['filname'] . "<br>";
    echo "History: " . $row['History'] . "<br>";
    echo "Date: " . $row['date'] . "<br>";
    echo "Image:";
    echo "<br>";

    // Add the input with image id value (I suppose it exist) 

    echo "<form name='rating' id='rating'>    
    <div id='rating-area' class='shadow'>


      <input type='hidden' name= 'image_id' value = $row[image_id]>


      <img src='stjärna.png' id='thumb1' data-value='1' />
      <img src='stjärna.png' id='thumb2' data-value='2' />
      <img src='stjärna.png' id='thumb3' data-value='3' />
      <img src='stjärna.png' id='thumb4' data-value='4' />
      <img src='stjärna.png' id='thumb5' data-value='5' />
    </div>
    </form>";
/。。。
while($row=mysqli\u fetch\u数组($result)){
$information='Titel:'。$row['Titel']。'Uppladdare:'。$row['Uppladdare']。'Filnamn:'。$row['filname']。'History:'。$row['History']。'DATA:'。$row['date'];
//将正确的信息打印到上传的图像中
回声“
”; echo“标题:”.$row['titel'].“
”; echo“Uploader:”.$row['upplader'].“
”; echo“Imagename:.$row['filname']。”
”; echo“History:”.$row['History']。“
”; 回显“日期:.”行['Date']。“
”; 回声“图像:”; 回声“
”; //添加带有图像id值的输入(我假设它存在) 回声“ ";
Ajax

<script>
    jQuery('div#rating-area img').click(function(e){
        // serialize the form and retrieve all value in PHP with $_POST['theNameOfInput']
        jQuery.post('post.php',{ form : $(this).serialize() },function(data,status){
            console.log('data:'+data+'/status'+status) ;
        }) ;
    }) ;

</script>

jQuery('div#评级区域img')。单击(函数(e){
//使用$\u POST['theNameOfInput']序列化表单并检索PHP中的所有值
jQuery.post('post.php',{form:$(this.serialize()},函数(数据,状态){
console.log('data:'+data+'/status'+status);
}) ;
}) ;
post.php

<?php

    $imageId = (int) $_POST['image_id'];
    // ... Your database treatments
    $sql = "UPDATE image SET image_rating = image_rating + 1 WHERE image_id = $imageId";
    //... Your code

点击()函数,您只需在数据库中增加rate的图像编号。如果增量为1,则不需要传递rate的值。要在SQL请求中进行总结,请参见
image\u rate=image\u rate+1
。我希望我没有错过要点。是的。不需要在文本文件中存储评级数据。将其存储在数据库中我会的,我已经阅读了y创建了一个数据库。看起来像:ImageRate ID Rate ImageID,但需要帮助连接并存储在其中。尝试实现一些功能,然后编辑您的问题。您只需将当前图像ID传递给隐藏字段(以您的形式)中的Rate。然后,将其传递给ajax请求,而不是
jQuery(this)。数据('value'))
。在你的
post.php
中,只需创建给定图像id的更新请求。不知道如何做。你能给我一个例子吗?但我是否需要数据库?图像在一个名为store“store”的数据库中。每个图像都有一个id,即PK。因此,我将所有图像的名称和$imageID交换为id,这是什么“image_rating”?感谢您的回答:)它对应于您图像的当前速率值。我明白了,当我尝试实现代码时,我遇到了一个错误:在那一行上显示了一个错误。但我真的不知道是什么错了。我的错误,我想您应该删除单引号$row[ID].整个建筑倒塌了。不管我怎么倒转,我都无法把它恢复到原来的位置。那将是一个地方。