2016-08-21 115 views
-3

<select name="filtering"> <option value="a">a</option> <option value="b">b</option> ,爲什麼不正確運行?

if (isset($_POST['filtering']) == "a") { 
    $stmt = prepare("SELECT * FROM user_posts ORDER BY post_time DESC LIMIT :limit OFFSET :offset"); 
} 

if (isset($_POST['filtering']) == "b") { 
    $stmt = prepare("SELECT * FROM user_posts ORDER BY post_time ASC LIMIT :limit OFFSET :offset"); 
} 
+0

Isset返回真/假 – 2016-08-21 07:41:00

回答

-1

Isset只會返回true或false

if (isset($_POST['filtering'])&&($_POST['filtering']=="a")){ 
    $stmt = prepare("SELECT * FROM user_posts ORDER BY post_time DESC LIMIT :limit OFFSET :offset"); 
} 

if (isset($_POST['filtering'])&&($_POST['filtering']=="b")) { 
    $stmt = prepare("SELECT * FROM user_posts ORDER BY post_time ASC LIMIT :limit OFFSET :offset"); 
} 
+0

它不能是A和B – 2016-08-21 08:03:25

+0

爲什麼它會返回a或b ?請澄清? –

相關問題