我在angularJs中创建了一个日历,并使用PHP来获取所有约会。
我有一张名为'估价'有很多行,但主要是'顾问'和'约会'
目前我正在通过顾问表中的所有顾问列表循环,然后检查每个顾问的所有约会,如下所示:
angular.forEach($scope.consultantsApps, function(item,key){
var appdate = new Date( moment(item.Appointment).format("YYYY-MM-DD"));
//removed my adding to calendar code as its not relevent but here is where i add the appointment to the calendar
}
});
这是我在consultantApps数组中为每位顾问运行的选择:
<?php
header('Content-Type: text/html; charset=utf-8');
$User = $_GET['user'];
require_once('sqlconnect.php');
$sqlQuery = "SELECT valuations.Company,
valuations.Ref, valuations.Appointment,
valuations.txtTime,
valuations.Town,
valuations.PostCode,
user.colorcode,
user.agencyname
FROM valuations
inner join user on user.agencyname = valuations.Consultant
WHERE user.id = $User order by valuations.Appointment desc LIMIT 20";
$result = $unity_connection->query($sqlQuery);
$json1 = array();
while($rows = mysqli_fetch_assoc($result)){
$json1[] = array_map('utf8_encode', $rows);
}
echo json_encode($json1);
?>
大约有20名顾问,每人约有400人,但我必须将速度限制在20人之间。
感谢您的帮助
答案 0 :(得分:0)
首先,您应该最终不要在请求中使用$ User(来自用户输入),以防止SQL注入。至少你应该逃避它(使用(int)
或$pdo->escape
)。最好使用prepared statement。
然后,根据您的请求,我认为您应该在用户表上进行SELECT,然后对估值进行加入:
SELECT valuations.Company,
valuations.Ref, valuations.Appointment,
valuations.txtTime,
valuations.Town,
valuations.PostCode,
user.colorcode,
user.agencyname
FROM user
inner join valuations on user.agencyname = valuations.Consultant
WHERE user.id = ? order by valuations.Appointment desc LIMIT 20