0

私のPHPファイルコードは次のとおりです。

<?php
require('config.inc'); //Init DB.

$current_user_id = $_GET['uid']; //Set User ID From AJAX GET.

mysql_query("USE social-network"); //Set MySQL DB.

$userFavs = "SELECT subscribee_id FROM subscribe WHERE subscriber_id = '" . $current_user_id . "'"; //Get people user is subscribed to.

$query="SELECT * FROM posts WHERE (post_owner_id IN ($userFavs) OR post_owner_id = '" . $current_user_id . "') ORDER BY id DESC"; //Select posts by user AND by people user is subscribed to.

$result=mysql_query($query); //Do the query.

$num=mysql_numrows($result); //Get number of rows in query.

$i=0; //Display selected posts.
while ($i < $num) {

$owner_id=mysql_result($result,$i,"post_owner_id");
$content=mysql_result($result,$i,"content");
$date=mysql_result($result,$i,"date");


$poi_query=mysql_query("SELECT firstname, lastname, profile_picture FROM `social-network`.`users` WHERE id = '" . $owner_id . "'") or die(mysql_error());
$post_firstname=mysql_result($poi_query, 0, "firstname");
$post_lastname=mysql_result($poi_query, 0, "lastname");
$post_profile_picture=mysql_result($poi_query, 0, "profile_picture");
?>

      <div class="post">
        <h1 class="post-title"><a href="profile.php?user=<?php echo $owner_id; ?>"><?php echo $post_firstname; ?> <?php echo $post_lastname; ?></a></h1>
        <p class="content"><?php echo $content; ?></p>
        <p class="details"><?php echo $date; ?></p>

      </div>

      <?php
$i++;
}
?>

これが私のJS AJAXリクエストです:

function loadPosts()
{
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","PHP/news-feed.php?uid=<?=$current_user_id?>",true);
xmlhttp.send();
document.getElementById("posts").innerHTML=xmlhttp.responseText;
}

マイページの投稿セクションに何も表示されません。私は何を間違っていますか?PHPコードはテスト済みで、投稿ページに直接含めただけで機能しました。私がやろうとしていること:リロードを使用した PHP ニュースフィード

4

2 に答える 2

0

ID「posts」の要素はどこですか?、post クラスの div タグしか見えません

于 2012-05-03T22:33:18.563 に答える
0

あなたの ajax で間違っていることの 1 つは、それが同期的であると想定していることです。リクエストを送信した直後に結果を期待していますが、代わりにイベントにイベント ハンドラーをアタッチする必要がありますonreadystatechange

ajax の経験がない場合は、jQueryなどのライブラリを使用して処理することをお勧めします。

それとは別に、あなたが ajax 関数を呼び出している場所もわかりません。

于 2012-05-03T22:38:28.283 に答える