PHP / MySql如果'1'回显“Ok”否则如果'0'回显“否”

时间:2015-12-05 22:54:37

标签: php mysql

PHPMYADMIN:

Phpmyadmin Image example

if (mysql_query("SELECT setup FROM users") === 1) {

echo "One";

} else if (mysql_query("SELECT setup FROM users") === 0) {

echo "Zero";

}

登记。根据定义:0。

如果表格显示0,则回显零点。 否则,如果表格显示ID 1,则回显一个。

这是怎么做到的?

解决方案:

$setup = mysql_query("SELECT setup FROM users");
$row = mysql_fetch_assoc($setup);

if ($row['setup'] == 0) {
    echo "Zero.";
} else {
    echo "One!";
}

2 个答案:

答案 0 :(得分:0)

请参阅docs。 '示例(MySQLi程序)'示例与您想要的类似。

段:

    ERROR: Call to undefined method DOMElement::appendData() 

更改

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "0 results";
}

mysqli_close($conn);
?>

$sql = "SELECT id, firstname, lastname FROM MyGuests";

然后

$sql = "SELECT setup FROM users";

你的各种检查应该足够了。不是最干净的。好像你可以打印出设置的价值?祝你好运!

答案 1 :(得分:0)

我认为你需要这个

首先使用mysqli

//$connection = your mysqli connection. Dont use mysql

如果您需要管理行

,请正确编写查询
$query = "SELECT `setup` FROM `users` WHERE `user_id`=1 AND `username` = 'admin'";

然后执行查询

$result = mysqli_query($connection, $query);

然后搜索$ setup value

while($row = mysqli_fetch_assoc($result)){
    $setup = $row['setup'];
}

然后回应你需要的东西

if ($setup == 1) {    
    echo "One";    
} else if ($setup == 0) {    
    echo "Zero";    
}