Sorry for my inexperience but I do not have a concrete idea of how to do the following. In a database table (project_snippets) in a table (code) I have four columns: id, code, author & link and id is the primary key. in the column code I want to enter several languages, until now PHP & Javascript but I wanted each code to have a table that separates sets where in turn has another, it would look something like
so far I was able to do the following.
try {
$conexion = new PDO('mysql:host=localhost;dbname=proyecto_snippets','root','');
} catch (PDOException $e) {
echo 'Error: ' . $e->getMessage();
die();
}
$statement = $conexion->prepare('SELECT * FROM code');
$statement->execute();
$codigos = $statement->fetchAll();
foreach ($codigos as $code) {
echo $code['id'] . ' - ' . $code['code'] . '<br>';
}
require 'views/index.view.php';
and the view would look like this
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Snippets</title>
<link rel="stylesheet" href="css/master.css">
</head>
<body>
<div class="contenedor">
<?php foreach ($codigos as $code): ?>
<div class="title">
<h1 class="title"><?php echo $code['code']; ?></h1>
<sub class="link">
<a href="<?php echo $code['link']; ?>" class="link" target="_blank">
<?php echo $code['autor']; ?>
</a>
</sub>
<button onclick="changeType('<?php echo strtolower($code['code']); ?>')" class="type" name="<?php echo strtolower($code['code']); ?>">VSCode</button>
</div>
<?php endforeach; ?>
</div>
<script src="js/master.js"></script>
</body>
</html>
If someone has enough pascience to tell me or tell me where to find an answer. Honestly, it's not urgent or necessary, I just do it to practice.