簡體   English   中英

如何使用php從mysql數據庫中獲取所有匹配的記錄?

[英]how to get all matching records from mysql database using php?

我在mysql數據庫中設置了下表

mem_id | pid | content
     0 |   1 | All the content is here
     0 |   2 | All the content is here
     0 |   3 | All the content is here

現在的問題是獲取所有匹配的mem_id值並將其存儲在php中的數組中。

示例:名為$id的變量的值為0

因此,現在我必須獲取列內容下的所有值,但只有與用戶的mem_id匹配的mem_id

誰能幫我這個忙,我需要在php中使用mysql查詢來獲取所有值。

我當前的代碼:

$con=mysqli_connect("localhost","*****","******","*****");

// Check connection
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM user_friends WHERE mem_id = '$_SESSION[SESS_MEMBER_ID]' LIMIT 1");

while($row = mysqli_fetch_array($result)) 
{ 
    $friends = $row['fid'];
} 
SELECT * FROM yourTABLE WHERE mem_id=0   // or 1 or 2 or 3 etc

使用PHP,您可以像這樣查詢它:

<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$id = intval($id);  // Put your ID here
$query = "SELECT * FROM yourTABLE WHERE mem_id=$id";
if ($result = mysqli_query($link, $query)) {
    while ($row = mysqli_fetch_assoc($result)) {
     print_r($row); 
    }
    mysqli_free_result($result);
}
?>
$query="select * from TABLE_NAME where `mem_id`='$id'";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM