English 中文(简体)
如何用新的数据重载在综合处理系统中的某一部分?
原标题:How to reload a certain part in a php file with new data?
  • 时间:2012-05-06 15:48:14
  •  标签:
  • php
  • mysql

I have a php file which retrieves data from a MySql database and display it. But the database have more no of data say 100. But in my php file I have planned to display 6 at a time just by using

LIMIT start_value, 6.

然后,在底部,我有一个包含以下法典的整段。

<a href="index.html?start_value=start_value+6">1</a>
<a href="index.html?start_value=start_value+12">2</a>
<a href="index.html?start_value=start_value+18">3</a>
<a href="index.html?start_value=start_value+24">4</a>
<a href="index.html?start_value=start_value+30">5</a>
<a href="index.html?start_value=start_value+36">6</a>

So now the issue is if anyone clicks the link above the whole index.html will be reloading which will be annoying. Is there any way to display the new data from the database just by reloading that particular DIV after clicking any of the links?

最佳回答

数据库中是否有新数据在点击任何链接后重新载重这一数据?

Yes, there is. You need to use the XMLHttpRequest object and DOM. In one word: AJAX

The best way is to use a framework like jQuery or Prototipe.

https://stackoverflow.com/questions/2595005/automatic-reload-of-div-container>Here 你可以找到一个例子。 例如,你应替换“最新得分......html”网页,并用另一页“最新得分......php”。 网址的文字将产生可放在主机上的新内容。

问题回答

You have two options:

  1. Ajax,这使你能够从服务器上检索数据,然后可以用来操纵OM。 Ajax是XMLHttpRequest的物体,使您能够完全检索 Java本背后的数据。 请注意,Ajax受Same Origin Policy的限制,但对于你所描述的罚款,则由你从同一来源装载数据。

  2. 框架(例如,<代码>iframes),你可以通过确定其弧内财产来装载内容。

其中,Ajax更为灵活。

参考/进一步读:


www.un.org/spanish/ecosoc <<<><<>><<<>>>>>>显然可直接使用>XMLHttpRequest 和“DOM”方法,但注意到存在交叉-browser 差异(和直接的bugs),这些差异可通过一个良好的图书馆如. 它们也提供了许多有用的实用功能,使你能够集中精力处理你试图解决的实际问题,而不是pl弄的细节。

例如,在此,你将如何向使用“ j”的服务器发出“Ajax”要求,并在网页上添加一个内容,同时以“超文本”碎片将服务器送回:

$("#target").load("get_the_data.php", {article: x});

也就是说:要求从收到__数据.php中提取一个超文本碎片,从x变数中提取该参数的物品,并将这种超文本碎片放在具有超文本“目标”的要素内。 如果你不使用图书馆,这将是一条十条良好的法典。 现在,这并非很多,而是重复了过去和现在的情况(在此过程中,我们正以粗略的眼光研究一些要素),你们看到它如何能够补充。

我确实建议你阅读上述参考资料,这样你知道图书馆是如何做的(不是魔鬼),但没有理由不利用辛勤工作的人来使这种困难更加容易。


如果你有一页,如索引.html?start_ Value=start_ Value+6,你可以这样做:

setInterval(myaction, 20000); //every 20 seconds

function myaction() {
  $("#quoteContainer").load("index.html?start_value=start_value+6");
}

You should look into jQuery javascript library which allows you to load content with ajax with ease because ajax is what you re looking for! PHP is a server side language, it works on the server and is not dynamic, you re looking for something working on the client side and that s Javascript.





相关问题
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 ...

热门标签