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 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换