如果我用244替換第一個%s,我可以得到沒有任何問題的總和。但是,在這種情況下使用動態值$ shot時,它看起來沒有任何東西,我的查詢也沒有成功,因爲其他結果都很好(例如stories.id,stories.title)。具有動態值的空SUM()
$query = sprintf("
SELECT
stories.id,
stories.title,
stories.timestamp,
stories.text,
users.name,
users.avatar,
users.id AS idus,
(SELECT sum(reviews.amount) FROM reviews WHERE reviews.storyid='%s') AS reviews
FROM stories INNER JOIN users ON stories.uid=users.id WHERE stories.id = '%s'",
mysql_real_escape_string($shot),
mysql_real_escape_string($shot));
出手就是從這裏來的:
$shot = $_GET['shot'];
+1逃脫^^ – span 2013-03-01 07:03:31
那麼你是否逃避了兩次字符串? – Passerby 2013-03-01 07:03:35
什麼是$射擊?當你var_dump時它說了什麼? – 2013-03-01 07:06:17