English 中文(简体)
与Javascript动态地改变购买力平价值
原标题:Changing a PHP value dynamically with Javascript

I m 制作一个博客类型的网页,上面有象样的异构体,上面的评级是类似/(类似+异构体)。 当用户点击类似或不喜欢时,我想在 d中增加他们的投票,并积极改变评级价值,而不重载页。 在这里,我只用了 j,所以任何帮助都是巨大的。

<div class="narrow_right_container">
   <?php 
    $popularity = get_popularity($row);
   ?>
   <div class="yellow_bg">Rating:  <?php echo $popularity . "%"; ?></div>
   <div style="margin-left:2px;">
    <div class="dislike">
       <a href="#"><img src="ui_images/dislike.png"/></a>
       <span>Dislike</span>
    </div>
    <div class="like">
       <a href="#"><img src="ui_images/like.png" /></a>
       <span>Like</span>
        </div>
   </div>
</div>
最佳回答
$( .like ).click(function(){
   rate(1);
})
$( .dislike ).click(function(){
   rate(-1);
})

function rate(_val){
$.ajax({
  url:  ajax/rate.php?val= +_val,
  success: function(data) {
    alert( Rate was performed. );
    $(".narrow_right_container").find(".yellow_bg").append("Rating: "+data+"%");
  }
});
}

www.un.org/Depts/DGACM/index_french.htm

if(isset($_GET[ val ])){
  $sql = "UPDATE.........."; //do an update to your rate table
  echo get_popularity($row); //return rating to ajax
}
问题回答

您实际上不会改变一种PHP值,因为这一页的输出到浏览器上,而PHP的再收成会与其互动,因为它在服务器上。 相反,想与浏览器中的文件互动。

这样做的最佳途径是向服务器面打字。 这种服务器侧面的文字可能会对数据库作出类似或不同的承诺,然后回去新的评级,你可以用javascript代替旧的评级。

You ll probably want to check out some tutorials on javascript and ajax, as it seems you have a more general need for a tutorial than for a specific problem. In other words, if you fill in your knowledge gaps on the general subject, you ll be able to solve your specific problem quite easily.

你们将想制定一些PHP代码,处理服务器一侧数据库的储蓄问题。 您将向该服务器的辅助稿提供类似/不相干的价值信息。 如果有可能,我将使用jQuery s AJAX,帮助将数据张贴到你刚创建的PHP网页。

与此类似:

$.ajax({
  url: "whatever.php",
  type: "POST",
  data: {Like: true},
  success: function(data){ /* update view */}
});

You will have to use ajax to accomplish this. Its not possible to alter PHP variables VIA javascript.

您必须指定一个Ajax功能,负责数据库的工作,并在该职能完成后,你必须使用javascript更新该数字。 这将使人相信,该数字已经更新,而该数字也将在数据库(Ajax)上更新。

Here is a great example of how you could accomplish this:

Example Code
Live Demo





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签