我想創建一個時間線來更新狀態以及它的評論,但我卡在while for
循環評論。它的所有循環的狀態是這樣的:父母和孩子while循環php
$_session['name1'] update:
lol
test comment //comment
test2 comment //comment
$_session['name2'] update:
lol2
test comment //comment
test2 comment //comment
我需要循環在剛剛父狀態子註釋,如何將這項代碼看看?還是使用類或函數?
輸出應該是這樣的:
$_session['name1'] update:
lol
test comment //comment
test2 comment //comment
$_session['name2'] update:
lol2
another comment //comment
到目前爲止我的代碼:
<?php
session_start();
require "koneksi.php";
echo 'selamat datang, '.$_SESSION['nama']." <a href='logout.php'>logout</a><br>";
?>
<form action='' method='POST'>
<h5>Update Status</h5>
<textarea name='textarea' cols='30' rows='3' placeholder="what's on your mind?"> </textarea><br>
<input type='submit'>
</form>
<?php
if(isset($_POST['textarea'])){
$text = $_POST['textarea'];
$pemilik = $_SESSION['nama'];
$sql1 = "INSERT INTO `home` VALUES(0,'$text','$pemilik')";
mysqli_query($conn,$sql1);
}
if(isset($_POST['comment'])){
$comment = $_POST['comment'];
$pemiliks = $_SESSION['nama'];
$sqlcom = "INSERT INTO `comment` VALUES(0,'$comment','$pemiliks')";
mysqli_query($conn,$sqlcom);
}
if(isset($_GET['del_stat'])){
$del = $_GET['del_stat'];
$delsSql = "DELETE FROM `home` WHERE `id`='$del'";
mysqli_query($conn,$delsSql);
}
if($query2 = mysqli_query($conn,$sql2 = "SELECT * FROM `home`")){
while($row = mysqli_fetch_assoc($query2)){
$stat = $row['id'];
echo '<table>';
echo '<tr>';
echo '<td>';
echo $row['pemilik'].' <font color=blue>post</font> ';
if($_SESSION['nama']==$row['pemilik']){echo "<a href=home.php?del_stat=$stat>delete</a>";}
echo '</td>';
echo '</tr>';
echo '<td>';
echo $row['timelines'];
if($results = mysqli_query($conn,$sql = "SELECT * FROM `comment`")){
while($theRows = mysqli_fetch_array($results)){
$roww = $theRows['comment'];
echo '<table>';
echo '<tr>';
echo '<td>';
echo $roww;
echo '</td>';
echo '</tr>';
echo '</table>';
}
}
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
?>
<form action='' method='POST'>
<textarea name='comment' rows='3' cols='20' placeholder='comment...'></textarea><br>
<input type='submit'>
</form>
<?php
echo '</td>';
echo '</tr>';
echo '</table>';
}
}
my database home for loop the updated status :
my database comment for loop the updated comment
我不能張貼2個鏈接的圖像爲輸出我不預期,所以我想輸出si milar這樣的:
Faddi Susanto post delete
hahahahahaha //comment belongs to Faddi Susanto
hello //comment belongs to Faddi Susanto
hello again //comment belongs to Faddi Susanto
s //comment belongs to Faddi Susanto
adi post delete
hohohohohohoho //comment belongs to adi
tes adi //comment belongs to adi
tes adi //comment belongs to adi
它像更新狀態
嗨,我編輯了我的帖子,包括數據庫。我只是問像父母和孩子一樣的循環,想知道它是否更清晰? – faddi
這並沒有多大幫助。我沒有看到任何外鍵連接兩個表之間的任何數據。表格和列名不適用於任何特別的東西。我無法幫助到目前爲止提供的內容。 – Ben