我有一个信息系统,更具体地说是一个信息系统,它是一个票务系统。信息系统将包含具有无限或“n”个用户量的帐户。我希望用户能够看到其他用户对新闻源内容的操作或更改。 (就像Facebook一样)。我将使用PHP,MySQL和AJAX(或jQuery)来实现新闻源。我会知道如何设置表和查询。如何创建新闻源(AJAX新闻源)
如何使用PHP和AJAX或jQuery来拉的内容和新闻推送显示它(带有淡入Facebook新闻风格或滚动效果?)。
我一直在寻找一个很好的教程,并没有找到一个。如果可能,我希望从头开始编码。
我仍然有一些问题:这是我有:
ajax.php
<?php require_once('../../Connections/f12_database_connect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_f12_database_connect, $f12_database_connect);
$query_newsfeed_a = "SELECT * FROM newsfeed";
$newsfeed_a = mysql_query($query_newsfeed_a, $f12_database_connect) or die(mysql_error());
while($row_newsfeed_a = mysql_fetch_assoc($newsfeed_a))
{
echo("<div class='feedItem'>");
echo("<div class='title'>" . $feedItem['title'] . "</div>");
echo("<div class='body'>" . $feedItem['body'] . "</div>");
echo("</div>");
}
$totalRows_newsfeed_a = mysql_num_rows($newsfeed_a);
?>
<?php
mysql_free_result($newsfeed_a);
?>
feed.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script>
function refreshNews()
{
$("#news").load("ajax.php")
}
</script>
</head>
<body>
<div id="news"></div>
</body>
</html>
我在做什么错?
我喜欢你的榜样。你可以让我从步骤1中看到你的PHP例子更详细些吗? –
另外,如何确保相同的信息不会被加载或显示多次? –
至于没有被多次显示,jQuery.load()设置对象的HTML意味着它应该替换已经存在的所有东西。所以它应该只显示来自最新请求的信息。 – Chris