我正在填写汽车经销店预订表格,我需要随机选择一名工作人员进行试驾我试过mt_rand()但我想我把它放错了位置````````````````````````````````````$sql = "INSERT INTO bookingcars (BookingStart, BookingEnd, BookingDate, MemberReference, ActivityID staffID) VALUES ('$timeStart', '$timeEnd', '$startDate', '$memberReference', '$activity', '$mt_rand(1, 4)staffID'";````````````````````````````````````
2 回答
天涯尽头无女友
TA贡献1831条经验 获得超9个赞
虽然您可以在查询中构建它,但是如果执行以下操作,它的清洁度会更高,并且更容易调试:
$staff=rand(1,4).'staffID'; // assume you wanted 1staffID .. ?
//or did you just want $staff=rand(1,4);
$sql = "INSERT INTO bookingcars (BookingStart, BookingEnd, BookingDate, MemberReference, ActivityID, staffID) VALUES ('$timeStart', '$timeEnd', '$startDate', '$memberReference', '$activity', '$staff')";
紫衣仙女
TA贡献1839条经验 获得超15个赞
另一种方法是在您的查询值中添加一个子查询,例如 ,...) VALUES (..., (SELECT DISTINCT (Id) FROM stalesstafftable order by Rand() limit 1))
- 2 回答
- 0 关注
- 172 浏览
添加回答
举报
0/150
提交
取消