I do not know how to express my question but the issue is this, I'm doing a job for a course which I'm taking but I'm at a standstill, the work basically consists in making a simple "copy" of a social network, These are the requirements that the teacher asks us:
1.Login / Register by user / password (Pre-populate the BD with at least 4 users, each with at least 6 tweets.)
2. Every user can publish a new Tuit.
3.A Tuit has: a user author, publication time and a message body that has a maximum limit of 140 characters.
4. See the timeline, which is the tweets published in chronological order by a user by selecting their name in one of their tweets.
5. See general timeline, that is, all the tweets published by all users, displayed in chronological order.
The project is already practically finished the problem lies specifically in that I got stuck at point number 4, to explain myself better and I managed to show the general timeline but what I can not do is that by clicking on the name from the user who posted that tweet, only the tuist that was published by that user will be displayed in another php. Here's the code for you to understand me better:
PHP code to show all the tweets:
As you can see I show the timeline dividing the query in rows, now the row ['user'] turned it into a link that sends me to the other php which should show the tweets of that user but this is where I have the problem because I do not know how to capture that user so I can send it in a variable to the other php file and only show me its tweets.
session_start();
$servername = "localhost";
$password = "";
$conn2 = mysqli_connect($servername,
"root",$password,"php_tweet_database");
$sql = 'SELECT user, publication, cuerpo FROM twett ORDER BY publication desc';
$_SESSION['userbusqueda'] = array();
if ($result = mysqli_query($conn2, $sql)){
while ($row = mysqli_fetch_array($result)) {
echo '<div>';
echo '<div id="usarioBuscar" >';
echo '<a href="../partials/individual.php?texto='.urlencode($row['user']).'">'.$row['user'].'</a>';
echo '</div>';
echo '<div>';
echo ''.$row["publication"].'';
echo '</div>';
echo '<div>';
echo ''.$row["cuerpo"].'';
echo '</div>';
echo "<br>";
echo '</div>';
$_SESSION['userbusqueda'] = $row['user'];
}
}
PHP code for a user's timeline:
Here basically what I want to do is to be able to bring from the other php the name of the user who was clicked on a variable to be able to use it within the sql sentence and only show me the tweets of that user.
session_start ();
$servername = "localhost";
$password = "";
$conn2 = mysqli_connect($servername,
"root",$password,"php_tweet_database");
/*LA VARIABLE $VAL SOLO LA PUSE PARA MOSTRARLES DONDE IRIA LA VARIABLE
QUE QUIERO LLAMAR DESDE EL OTRO PHP*/
$sql = "SELECT user, publication, cuerpo FROM twett WHERE user = '$val'";
if ($result = mysqli_query($conn2, $sql)){
while ($row = mysqli_fetch_array($result)) {
echo $row["user"]." ".$row["publication"]."<br>".$row["cuerpo"]."<br><br>";
}
} else {
echo "NO SE ENCONTRARON RESULTADOS";
}
I would be very grateful if you could give me ideas on how to solve this problem, I'm just starting on this and the truth is that my teacher is not that it helps a lot.