如何在“onclick"上在 MySQL 中显示下一个结果?在 JavaScript 中? [英] How do I show next result in MySQL on "onclick" in JavaScript?

查看:42
本文介绍了如何在“onclick"上在 MySQL 中显示下一个结果?在 JavaScript 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一定数量的结果(比如 5 个)并制作:

并使用 onlick 显示接下来的 5 个结果.

EDIT ::HTML

<div class="result"></div><div class="result"></div><div class="result"></div>

<a href="#" id="showMore"/>显示更多</a>

JAVASCRIPT使用 Jquery 如下

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></脚本><script type="text/javascript">$(函数(){$('#showMore').click(function(event) {event.preventDefault();$number = $('.result').size();$.ajax({类型:POST",网址:getNext.php",数据:计数=$数字",成功:功能(结果){$('#results').append(results);}});});});

PHP

你应该创建一个新的php页面(getNext.php)来获取查询结果

帮助

你可以使用类似

的 SQL

SELECT x,xx,xxx FROM XxXxXs 限制 $_POST['count'],5

I want to show a certain amount of results (say, 5) and make a:

<a href="" onclick="<?php ShowNextResult(); ?>">

And use onlick to show the next 5 results.

解决方案

EDIT :: HTML

<div id="results">
   <div class="result"></div>
   <div class="result"></div>
   <div class="result"></div>
</div>
<a href="#" id="showMore" />Show more</a>

JAVASCRIPT Use Jquery as below

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<script type="text/javascript">
$(function(){
      $('#showMore').click(function(event) {
         event.preventDefault();
         $number = $('.result').size();

        $.ajax({
           type: "POST",
           url: "getNext.php",
           data: "count=$number",
           success: function(results){
             $('#results').append(results);
           }
         });

      });

});
</script>

PHP

you should make a new php page (getNext.php ) that will get query results

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons LIMIT {$_POST['count']},5");

while($row = mysql_fetch_array($result))
  {
  echo "<div class='result'>".$row['FirstName'] . " " . $row['LastName']."</div>";
  }

mysql_close($con);
?>

HELP

you can use SQL something like

SELECT x,xx,xxx FROM XxXxXs Limit $_POST['count'],5

这篇关于如何在“onclick"上在 MySQL 中显示下一个结果?在 JavaScript 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆