douji6667 2013-11-16 13:30
浏览 53
已采纳

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

I have the following table set in my mysql database

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

Now the problem is to get all matching mem_id values and store it in a array in php.

Example: A variable called $id has value 0

So now I have to get all values under the column content but only those which matches the mem_id of the user.

Could anyone help me with this, I need it in php and using mysql query to get all the values.

My current code:

$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'];
} 
  • 写回答

2条回答 默认 最新

  • dongzhong9055 2013-11-16 13:35
    关注
    SELECT * FROM yourTABLE WHERE mem_id=0   // or 1 or 2 or 3 etc
    

    Using PHP you could query it like:

    <?php
    $link = mysqli_connect("localhost", "my_user", "my_password", "world");
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s
    ", 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条)

报告相同问题?

悬赏问题

  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?