a have small problem with my script.
I have data on database. But I need to use the data from one table in the same table. And I do not know how to make it exactly to make it work I tried I created some features but they wrote it to me.
$sql = "SELECT header,text,user_id FROM posts";
$result = $con->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
<? echo $row["text"]; ?>
}
}
This code work But when I put it again in it to find out the name of the user so it does not
$sql = "SELECT header,text,user_id FROM posts";
$result = $con->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
<? echo $row["text"]; ?>
$sql = "SELECT name FROM users WHERE id='$row["user_id"]'";
$result = $con->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
<? echo $row["name"]; ?>
}
}
}
}
This not working..I d know how fixed.
Tutorials how to do it better will be appreciated.
Thanks