我只需要创建一个简单的php页面,它可以查询一个表(ad_data),并将两列与另一个表中的行进行比较(time_clock_data),并返回time_clock_data中“Login Name”列的值。但是,当我运行页面时,它会从ad_data中提取所有内容,但time_clock_data'登录名'将返回null。
这是我的代码:
<?php
mysql_connect("localhost", "root", "") or die (mysql_error ());
$conn = new mysqli("localhost", "root", "", "uh_time_clock");
mysql_select_db("uh_time_clock") or die(mysql_error());
function queryAd(){
$adQuery = mysql_query("SELECT * FROM ad_data ORDER BY 'First Name' DESC");
while($ad = mysql_fetch_array($adQuery)) {
$adFirstName = $ad['First Name'];
$adLastName = $ad['Last Name'];
$adLoginName = $ad['Login Name'];
echo "<li>" . $adLoginName . "</li>";
mysql_select_db("uh_time_clock") or die(mysql_error());
$tcQuery = "SELECT * FROM time_clock_data WHERE 'First Name' = '$adFirstName' and 'Last Name' = '$adLastName'";
$tc = mysql_fetch_assoc( mysql_query($tcQuery) );
$tcLoginName = $tc['Login Name'];
echo "<li>" . $tcLoginName . "</li>";
}
}
queryAd();
mysql_close();
?>