如何在 PHP 中使用提取

How to use a fetch in PHP

我写了下面的代码:

        <?php
$db_host="localhost";
$db_user="root";
$db_pass="";
$db_name="formend";
$db_table="jadval";
$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");
$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
$dbresult=mysql_query("SELECT * FROM `jadval`");
while ($amch = mysql_fetch_assoc($dbresult)) {
    echo $amch["id"];
    echo $amch["name"];
}
?>

但这不起作用 只有一页是空的 请帮助我...

改用 mysqli_*,因为 mysql_* 已在 PHP 5.5 中弃用并在 PHP 7 中删除:

<?php
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "formend";
$db_table = "jadval";
$con = mysqli_connect($db_host, $db_user, $db_pass, $db_name) or die("خطا در اتصال به پايگاه داده");

$dbresult = mysqli_query($con, "SELECT * FROM `jadval`");
while ($amch = mysqli_fetch_array($dbresult)) {
    echo $amch["id"];
    echo $amch["name"];
}
?>

PDO 将在 12 个不同的数据库系统上工作,而 MySQLi 将仅在 MySQL 数据库上工作。 (来自 w3schools)

使用 PDO:

<?php
$servername = "localhost";
$username = "root";
$password = "";

try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
}catch(PDOException $e){}
$sth = $conn->prepare("SELECT * FROM jadval");
$sth->execute();

/* Fetch all of the remaining rows in the result set */
 print("Fetch all of the remaining rows in the result set:\n");
 $result = $sth->fetchAll();
 print_r($result);

希望对您有所帮助!

根据您的代码:

    <?php
$db_host="localhost";
$db_user="root";
$db_pass="";
$db_name="formend";
$db_table="jadval";
$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");
$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
$dbresult=mysql_query("SELECT * FROM jadval");
while ($amch = mysql_fetch_array($dbresult)) {
    echo $amch["id"];
    echo $amch["name"];
}
?>

而不是 mysql_fetch_assoc,您应该使用 mysql_fetch_array。