gpt4 book ai didi

php - mysql_query如何显示if条件的html

转载 作者:行者123 更新时间:2023-11-29 13:01:04 27 4
gpt4 key购买 nike

所以我有这个质朴和基本的php,它将检查我的数据库中的值,如果它正确,它将拉出该行的其余部分,我猜,但我的问题是如果结果正常的话如何回显某些html以及如何回显其他一些 html if else。

顺便说一句,atm else 不起作用,换句话说,如果您输入不在我的数据库上的代码,它不会显示任何内容

<?php
$db_hostname = 'localhost';
$db_database = 'codedb';
$db_username = 'root';
$db_password = '';
$table = 'users';
$field = 'code';
$test = 'first_name';


// Connect to server.
$connection = mysql_connect($db_hostname, $db_username, $db_password) OR DIE ("Unable to
connect to database! Please try again later.");

// Select the database.
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());

$query = "SELECT * FROM $table WHERE $field = '{$_GET["qcode"]}'";
$result = mysql_query($query);
if ($result) {
while($row = mysql_fetch_array($result)) {
$name = $row["$field"];
$test = $row["$test"];
echo "Hello: $name $test";
}
}
else {
echo "Im sorry you buddy, you are not a winner this time! $test";
}
mysql_close($connection);
?>

最佳答案

您可以使用mysql_num_rows() ,这是最好的办法。

if( mysql_num_rows($result) > 0 ){
/* Anything you want here on success */
} else {
/* Anything you want here on failure */
}

关于php - mysql_query如何显示if条件的html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23332206/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com