我有一个PHP脚本来回显db中存在的db表的名称,但现在我只想回复那些记录在表中的用户。
这是我目前的剧本:
if ( !$conn ) {
die("Connection failed: " . mysqli_connect_error());
}
$tablesquerys = "SHOW TABLES";
$tableresults = mysqli_query($conn, $tablesquerys) or die(mysqli_error($conn));
if ( mysqli_num_rows($tableresults) > 0 ) {
echo "<select id='dbtable_selector' class='dbtable-selector'>";
echo "<option value='Current Tables' selected='selected'>Current Files</option>";
while( $table = mysqli_fetch_array($tableresults, MYSQLI_NUM) ) {
echo("<option value='" . $table[0] . "'>" . $table[0] . "</option>");
}
echo "</select>";
}
mysqli_close($conn);
要比较的用户名存储在$currentuser
我的第二次尝试:
if ( !$conn ) {
die("Connection failed: " . mysqli_connect_error());
}
$tablesquerys = "SHOW TABLES";
$tableresults = mysqli_query($conn, $tablesquerys) or die(mysqli_error($conn));
if ( mysqli_num_rows($tableresults) > 0 ) {
echo "<select id='dbtable_selector' class='dbtable-selector'>";
echo "<option value='Current Tables' selected='selected'>Current Files</option>";
while( $table = mysqli_fetch_array($tableresults, MYSQLI_NUM) ) {
$userquerys = "SELECT username FROM `" . $table[0] . "`";
if ( mysqli_query($conn, $userquerys) ) {
if ( $userquerys === $currentuser ) {
echo("<option value='" . $table[0] . "'>" . $table[0] . "</option>");
}
} else {
echo "Error updating record: " . mysqli_error($conn);
}
}
echo "</select>";
}
mysqli_close($conn);
仍然没有回音或任何错误。
好的,我看到上面尝试的缺陷,所以这是我的第三次尝试:
if ( !$conn ) {
die("Connection failed: " . mysqli_connect_error());
}
$tablesquerys = "SHOW TABLES";
$tableresults = mysqli_query($conn, $tablesquerys) or die(mysqli_error($conn));
if ( mysqli_num_rows($tableresults) > 0 ) {
echo "<select id='dbtable_selector' class='dbtable-selector'>";
echo "<option value='Current Tables' selected='selected'>Current Files</option>";
while( $table = mysqli_fetch_array($tableresults, MYSQLI_NUM) ) {
$userquerys = "SELECT username FROM `" . $table[0] . "`";
if ( mysqli_query($conn, $userquerys) === $currentuser ) {
echo("<option value='" . $table[0] . "'>" . $table[0] . "</option>");
}
}
echo "</select>";
}
mysqli_close($conn);
仍然没有。