To achieve this, you can use PHP to query the database for the “mark_allow” field from Table1 and then use that result to query Table2 for the corresponding “comments” field. Here’s a basic example of how you can do this:
php
// Assuming you have already established a database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Query Table1 for the mark_allow field
$sql = "SELECT mark_allow FROM Table1 WHERE " ;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Output data of each row
while($row = $result->fetch_assoc()) {
// Use the mark_allow value to query Table2 for the corresponding comments
$mark_allow = $row["mark_allow"];
$sql2 = "SELECT comments FROM Table2 WHERE mark_allow = '$mark_allow'";
$result2 = $conn->query($sql2);
if ($result2->num_rows > 0) {
// Output data of each row
while($row2 = $result2->fetch_assoc()) {
echo "comments: " . $row2["comments"] . "
";
}
} else {
echo "0 results";
}
}
} else {
echo "0 results";
}
$conn->close();
?>
Replace
with the condition that suits your needs to select the desired rows from Table1. Also, make sure to replace the placeholder values for the database connection ($servername
, $username
, $password
, $dbname
) with your actual database credentials.
المزيد من المعلومات
للبداية، يجب عليك إنشاء اتصال بقاعدة البيانات في PHP. يمكنك استخدام الدالة mysqli_connect
لهذا الغرض. السطور التالية توضح كيفية الاتصال بقاعدة البيانات:
php$servername = "localhost"; // اسم خادم قاعدة البيانات
$username = "اسم_المستخدم"; // اسم المستخدم للدخول إلى قاعدة البيانات
$password = "كلمة_المرور"; // كلمة المرور للدخول إلى قاعدة البيانات
$dbname = "اسم_قاعدة_البيانات"; // اسم قاعدة البيانات التي ترغب في الاتصال بها
// إنشاء اتصال بقاعدة البيانات
$conn = mysqli_connect($servername, $username, $password, $dbname);
// التحقق من نجاح الاتصال
if (!$conn) {
die("فشل الاتصال: " . mysqli_connect_error());
}
بعد ذلك، يمكنك استخدام استعلام SQL لاسترجاع قيمة mark_allow
من Table1
باستخدام دالة mysqli_query
. يمكنك ذلك كما في الكود التالي:
php$sql = "SELECT mark_allow FROM Table1 WHERE " ;
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$mark_allow = $row["mark_allow"];
// استخدام قيمة mark_allow لاسترجاع الـ comments من Table2
$sql2 = "SELECT comments FROM Table2 WHERE mark_allow = '$mark_allow'";
$result2 = mysqli_query($conn, $sql2);
if (mysqli_num_rows($result2) > 0) {
while($row2 = mysqli_fetch_assoc($result2)) {
echo "comments: " . $row2["comments"] . "
";
}
} else {
echo "0 results";
}
}
} else {
echo "0 results";
}
يرجى استبدال
بالشرط الذي يناسب احتياجاتك لتحديد الصفوف المطلوبة من Table1
. كما يجب استبدال القيم المؤقتة لاتصال قاعدة البيانات ($servername
, $username
, $password
, $dbname
) ببيانات الاتصال الفعلية.