我正在尝试进行座位预订系统,如果座位X可用,我需要通过MySQL查询。如果指定了名称,则打印“Not Avalible”,否则如果没有指定名称,则打印“available!”。
我成功编写了一个有效的代码,但现在我需要将它更新到新的MySQLi库。这是旧MySQL库的代码:
<?php
$link = mysql_connect(localhost, root, root);
mysql_select_db(V3);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$i=0;
$number = 1;
$letter = 'A';
while ($i<336){
if($number > 14){
$letter++;
$number = 1;
}
$seat = $letter . $number;
$result = mysql_query("SELECT name FROM seats WHERE seat = '$seat'");
if( $r = mysql_fetch_assoc($result) ){
if( $r['name'] == '' ){
print 'Avalible';
}else{
print 'Not Avalible';
}
}
$i++;
$numero++;
}
?>
这是我尝试使用新的MySQLi库:
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "V3";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$i=0;
$number = 1;
$letter = 'A';
while ($i<336){
if($number > 14){
$letter++;
$number = 1;
}
$seat = $letter . $number;
$result = mysql_query("SELECT name FROM seats WHERE seat = '$seat'");
if( $r = mysql_fetch_assoc($result) ){
if( $r['name'] == '' ){
print 'Avalible';
}else{
print 'Not Avalible';
}
}
$i++;
$numero++;
}
当然,它不起作用。它什么都不打印。帮助