2016-11-18 41 views
1

我需要檢查分配給用戶帳戶數據庫值,如果這個值是0加載頁面時的重定向(或小於1?)PHP/MySQL的重定向頁面,如果表中的值是0

代碼是有該函數是:

// ****************************************************** 
// JAY CHECK SCREENINGS FUNCTION 
function CheckScreenings() { 

if (!empty($_SESSION['userId'])) { 
    $conn = connectToDB(); 

     if (!$conn) { die('Could not connect: ' . $conn->errorInfo()); } 
    $checkquery = ("SELECT screenings FROM screener_users WHERE user_id = '" . $_SESSION['userId'] . "';"); 
    foreach ($conn->query($checkquery) as $row) 
     { 
      $screenings = $row[0]; 
     } 

    if ($screenings == 0) 
    { 
     header("Location: http://example.com/myOtherPage.php"); 
     die(); 
    } 
} 
} 
// ****************************************************** 

我也是,在另一頁需要隱藏2頁的超鏈接,如果此相同的值是0

<li> 
    <a href="/screener-test">Take a new test</a> 
</li> 
<li style="margin-bottom: 20px;"> 
    <?php $lastTest = getUserLatestIncompleteTest($user_id); ?>        
    <a href="/screener-test?test_id=<?php echo $lastTest[0]; ?>">Continue last incomplete test</a> 
</li> 

任何想法?

感謝, Ĵ

+0

問題是什麼? – RST

+0

似乎沒有選擇$屏幕 - 總是將其視爲0並在if屏幕== 0部分中運行代碼。 –

+0

確保你的'$ conn-> query($ checkquery)'函數返回一個數組 –

回答

0

如果你的函數做什麼,我覺得他們做的東西寫的

$result_rows = $conn->query($checkquery); 
if (count(result_rows) == 0) { 
    header("Location: http://example.com/myOtherPage.php"); 
} 

應該工作。