繁体   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