Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php从mysql数据库中获取所有匹配的记录?_Php_Mysql - Fatal编程技术网

如何使用php从mysql数据库中获取所有匹配的记录?

如何使用php从mysql数据库中获取所有匹配的记录?,php,mysql,Php,Mysql,我在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\u id值,并将其存储在php中的数组中 示例:名为$id的变量具有值0 因此,现在我必须获取列内容下的所有值,但只获取与用户的mem\u id匹配的

我在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\u id
值,并将其存储在php中的数组中

示例:名为
$id
的变量具有值
0

因此,现在我必须获取列内容下的所有值,但只获取与用户的
mem\u 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'];
} 
使用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);
}
?>

<?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'";