我在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
匹配的值。
任何人都可以帮助我,我需要在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'];
}
答案 0 :(得分:1)
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);
}
?>
答案 1 :(得分:0)
$query="select * from TABLE_NAME where `mem_id`='$id'";