Saya bisa mengerti bagaimana saat pertama kali memulai. Setelah Anda membungkus pikiran Anda dengan bagian dasarnya, sisanya akan mengalir.
Karena Anda meminta cara yang lebih baik, saya akan menyarankan kelas yang saya gunakan secara pribadi di semua proyek saya.
https://github.com/joshcam/PHP-MySQLi-Database-Class
Tentu saja jangan lupa untuk mengunduh kelas MYSQLI sederhana dari tautan di atas dan sertakan seperti yang saya lakukan di bawah ini dalam proyek Anda. Jika tidak, semua ini tidak akan berhasil.
Di sini kami halaman pertama yang berisi tabel dengan semua pengguna dari tabel Db orang Anda. Kami mencantumkannya dalam tabel dengan tombol edit/lihat sederhana.
HALAMAN 1
<?php
require_once('Mysqlidb.php');
//After that, create a new instance of the class.
$db = new Mysqlidb('host', 'username', 'password', 'databaseName');
//a simple select statement to get all users in the DB table persons
$users = $db->get('persons'); //contains an Array of all users
?>
<html>
<head>
<link type="text/css" href="style.css">
</head>
<body>
<table>
<th>
First Name
</th>
<th>
Last Name
</th>
<th> </th>
<?php
//loops through each user in the persons DB table
//the id in the third <td> assumes you use id as the primary field of this DB table persons
foreach ($users as $user){ ?>
<tr>
<td>
<?php echo $user['fname'];?>
</td>
<td>
<?php echo $user['lname'];?>
</td>
<td>
<a href="insert.php?id=<?php echo $user['id']; ?>"/>Edit/View</a>
</td>
</tr>
<?php } ?>
</table>
</body>
</html>
Jadi itu mengakhiri halaman pertama Anda. Sekarang Anda perlu memasukkan kode ini pada halaman kedua Anda yang kami asumsikan disebut insert.php.
HALAMAN 2
<!--add this to your insert page-->
<?php
require_once('Mysqlidb.php');
//After that, create a new instance of the class.
$db = new Mysqlidb('host', 'username', 'password', 'databaseName');
//a simple select statement to get all the user where the GET
//variable equals their ID in the persons table
//(the GET is the ?id=xxxx in the url link clicked)
$db->where ("id", $_GET['id']);
$user = $db->getOne('persons'); //contains an Array of the user
?>
<html>
<head>
<link type="text/css" href="style.css">
</head>
<body>
<table>
<th>
First Name
</th>
<th>
Last Name
</th>
<th>user ID</th>
<tr>
<td>
<?php echo $user['fname'];?>
</td>
<td>
<?php echo $user['lname'];?>
</td>
<td>
<?php echo $user['id']; ?>
</td>
</tr>
</body>
</html>