1

我在尝试为时间预订系统加入几张桌子时遇到了一些麻烦。

数据库如下所示:

数据库表:

tbl_events

- int_eventID (INT)
- int_serviceID (INT)
- date_eventDueDate (DATETIME)
- date_eventCreationDate (DATETIME)
- int_userID (INT)
- int_customerID (INT)
- int_eventOnlineBooked (INT)

tbl_customers

- int_customerID (INT)
>>> - int_userID (INT) <= this one gives me headache << 
- str_customerFirstName (VARCHAR)
- str_customerLastName (VARCHAR)
- str_customerEmail (VARCHAR)
- str_customerPassword (VARCHAR)
- str_customerCellPhone (VARCHAR)
- str_customerHomePhone (VARCHAR)
- str_customerAddress (VARCHAR)

tbl_services

int_serviceID (INT)
str_serviceName (VARCHAR)
str_serviceDescription (VARCHAR)
int_servicePrice (INT)
int_serviceTimescale (TIME)

tbl_users

int_userID   (INT)
str_userFirstName (VARCHAR)
str_userLastName (VARCHAR)
str_userEmail (VARCHAR)
str_userPassword (VARCHAR)
str_userCellPhone (VARCHAR)

我的一切都按 SQL 查询的预期工作(见下文)。它为我提供了特定周内特定“用户”的所有事件。

SQL查询:

SELECT  int_customerID as customerID,
    int_serviceID as serviceID,
    int_eventID as eventID,
    date_eventDueDate as eventDueDate,
    date_eventCreationDate as eventCreationDate,
    int_eventOnlineBooked as eventOnlineBooked,
    str_serviceName as serviceName,
    int_serviceTimescale as serviceTimescale,
    str_customerFirstName as customerFirstName,
    str_customerLastName as customerLastName,
    str_customerCellPhone as customerCellPhone,
    str_customerHomePhone as customerHomePhone
FROM tbl_events
JOIN tbl_services USING (int_serviceID)
JOIN tbl_customers USING (int_customerID)
WHERE
int_userID = 1 AND
YEARWEEK(date_eventDueDate,1) = 201219

问题是,我在 tbl_customers 表中没有指定该客户属于哪个用户的列。当我将“int_userID”添加到 tbl_customers 时,SQL 停止工作并给了我错误消息:

<b>Warning</b>:  mysql_num_rows() expects parameter 1 to be resource, boolean given in     <b>/Library/WebServer/Documents/calendar/api/calender_getWeekGetEvents.php</b> on line <b>46</b><br />

第 46 行:

if(mysql_num_rows($result)) {
    while($event = mysql_fetch_assoc($result)) {
        $events[] = $event;
    }
}

有任何想法吗?:)

谢谢/L

4

2 回答 2

3

如果列名发生冲突,请尝试指定您尝试使用哪个表。

...
WHERE
tbl_Events.int_userID = 1 AND
...
于 2012-05-17T09:45:58.440 回答
1

在多个表中使用相同字段名的 JOIN 查询中,最好使用别名作为表名。

于 2012-05-17T09:47:55.943 回答