我正在設置代碼來設置您的帳戶我有一個IF語句,如果total_not < = 40它不得不做任何事情,因爲你已經達到了最大通知。但是這不起作用我該如何解決這個問題?如果聲明不起作用,如果達到最大值
代碼:
<?php
// Set the database access information (add your own database credentials below)
xxxxx
// Connect to the database
$dbc = @mysqli_connect ($db_host, $db_user, $db_password, $db_name) OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
// Check for shout removal
// Check for shout submission
if(isset($_POST['submit']))
{
// Empty error array
$error = array();
// Check for a shout
if(empty($_POST['email']))
{
$error[] = "Oeps! Er is iets fout gegaan!";
}
// If there are no errors, insert shout into the database.
// Otherwise, display errors.
if(sizeof($error) == 0)
{
// Clean data
$mijn_les = $_POST['mijn_les'];
$email = mysqli_real_escape_string($dbc, $_POST['email']);
// Insert shout
$query = "UPDATE users SET user_email = '$email', user_tid = '$mijn_les' WHERE user_name = '{$_SESSION['user_name']}'";
$result = @mysqli_query($dbc, $query) or die('Query failed: ' . mysqli_error($dbc));
// Display confirmation
echo "<div class='alert alert-success'>
<strong>Gelukt!</strong> Je account is ingesteld! <a href='../signin.php?logout' class='alert-link'>Klik hier</a> om opnieuw in te loggen!
</div>";
$hide = "style='display: none;'";
$num_rows = $result->num_rows;
if($num_rows <= 40)
{
$send_not = "INSERT INTO notif (send_to, grav_url, send_by, notif_text) VALUES ('{$_SESSION['user_name']}', 'http://www.gravatar.com/avatar/a72776fb2702ba915e2327618414bb15', 'Admin', 'Leraar Setup compleet! U kunt nu onze website gebruiken!')";
$not_add = @mysqli_query($dbc, $send_not) or die('Query failed: ' . mysqli_error($dbc));
}
} else {
// Display error message
foreach($error as $value)
{
echo "<div class='alert alert-danger'>
<strong>Oeps!</strong> Er is iets mis gegaan! Probeer het opnieuw!
</div>";
}
}
}
?>
'num_rows':獲取一個結果集,這意味着更新的結果是永遠不會'> = 40'與此插入查詢將行數每次執行'INSERT INTO notif'。爲了解決這個問題,你應該添加一個'select count(id_notif)from notif where ...',然後你可以使用'num_rows'的值# – 2015-02-06 15:15:16
'num_rows'從'select'獲取行數,你是'update 'ING。試試'affected_rows'。但它看起來只會是'1'。 – AbraCadaver 2015-02-06 15:33:39
@Simo讓它成爲謝謝你的答案! – 2015-02-06 15:34:42