dongyuan7110 2014-05-10 19:46
浏览 35

让php脚本多次运行

I have a system where a PHP script uses MySQL to get info based on a user. Then, based on that information, a certain button will be displayed. The database that is being called has columns:

id
user_one
user_two

This is meant to check if two users are friends. However, my problem is that if a user has more that 1 friend the script only works for the 1st friend.

$select_friends_query = mysql_query("SELECT friend_id FROM friends WHERE user_id = '$user'");
 while($friend_row = mysql_fetch_assoc($select_friends_query)) {
$friend = $friend_row['friend_id'];
}

if ($username == $friend) {
 $addAsFriend = '<input type="submit" class = "frnd_req" name="removefriend" value="Disassociate">';
}

else
{
 $addAsFriend = '<input type = "submit" class = "frnd_req" name = "addfriend" value = "Send Associate Request">';
 }
}
}

Then I have echo $addAsFriend later.

  • 写回答

2条回答 默认 最新

  • dongzuoyue6556 2014-05-10 19:50
    关注

    You have to look over all results. Like the while loop example in http://www.php.net/manual/en/function.mysql-fetch-assoc.php

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序