I am trying to build a list of links that point to a template, where one of the variables, with the contents of one of the fields in the table, must be dynamically informed in the template (being associated with a specific row in the table) p>
The code that generates the list:
require_once("conexao.php");
$sql = "SELECT 'username', 'userid' FROM 'banco' WHERE username='$user_name'"; // aqui ele pega o username do usuário logado pra gerar a lista buscando no BD
$query = $mysqli->query($sql);
while ($dados = $query->fetch_assoc()) { //alguns dados
echo '<div>';
echo '<br>Nome: ' . $dados['username'] . ' ';
echo 'ID: ' . $dados['userid'] . ' ' <br><br>';
// e aqui é pra gerar a lista de links pra essa template
echo "
<a href='template.php'>Ir para a template e informar qual linha deve ser pega na variável </a>
";
echo '</div>';
}
The field I want to get is generated like this:
// BASE
ob_start();
include "../saida.php";
$output = ob_get_clean();
file_put_contents('filename', $output);
echo $output;
?>
I have SQL that records this data in the database, in a text long
field, and so far everything is fine ...
On the template page the code looks like this:
require_once("conexao.php");
$sql = "SELECT 'campo' FROM 'banco' WHERE username='$user_name'";
$query = $mysqli->query($sql);
while ($dados = $query->fetch_assoc()) {
echo utf8_encode($dados['campo']);
}
So it takes all the results, and returns all the contents of this table field associated with the logged in user, and writes one result below the other ... now I wanted to generate a list of links, and generate a template to bring the content of each specific row of the table, with the field associated with the row of the table that generated the link. (ah, I hope it's not getting any more confusing: P) ...
I thought it would be the case to create a for
or foreach
to generate this variable dynamically, and inform the table line to be taken (via URL?) in the template page, but I do not know if it is the ideal , I do not know how to do this, I'm really confused here ... :): /