大家好,
我需要一些php和MySQL查询的帮助。我有一个来自GitHub的人提出的应用程序,我想根据我的需要稍微修改一下。 aplications是来自pbxinaflash的FIAS-PMS,巫婆你可以签到,结账并设置一个分机的唤醒电话。目标是为办公室和来宾使用的扩展创建不同的报告。为客人提供完美的工作。
代码如下所示:
$dbconnection = mysql_connect($dbhost, $dbuser, $dbpass) or die("Database connection failed");
mysql_select_db($dbname) or die("data base Hotel-Rooms open failed");
$query = "SELECT `ID`, `Desc` FROM `Rooms` ORDER BY `Desc` ASC";
$result = mysql_query($query) or die ("Couldn't execute SQL query on Hotel-Users table.") ;
mysql_close($dbconnection);
echo " <SELECT ID=\"RoomsComboBox\" NAME=\"RoomsComboBox\">";
echo "<OPTION VALUE=\"ALL\" SELECTED> ".$SecLab22." </OPTION>";
while ($row = mysql_fetch_array($result)) {
echo "<OPTION VALUE=\"$row[0]\">" . $row[1] . "</OPTION>";
}
echo "</SELECT>";
echo "</TD>" ;
echo "<TD><INPUT TYPE=\"SUBMIT\" NAME=\"SearchButton\" VALUE=\"".$SecLab21."\"></TD>\n" ;
echo "</TR>\n" ;
echo "</TABLE></div>\n";
echo "</FORM>\n";
if(isset($_POST['SearchButton'])) :
echo
"<TABLE cellSpacing=0 cellPadding=0 width=900 border=0>\n" ;
echo "<TR><TD>Id</TD><TD>".$SecLab7."</TD><TD>".$SecLab14."</TD><TD>".$SecLab15."</TD><TD>".$SecLab17."</TD><TD>".$SecLab31."</TD><TD>".$SecLab1."</TD>" ;
$dbconnection
= mysql_connect($dbhost, $dbuser, $dbpass) or die("Database connection failed");
mysql_select_db($dbname) or die("data base Hotel-Rates open failed");
$between = '';
$room = '';
$query = "SELECT * FROM `Users`";
$RoomsComboBox = $_POST['RoomsComboBox'];
$FROMD = $_POST['FROMD'] ;
$FROMM = $_POST['FROMM'] ;
$FROMY = $_POST['FROMY'] ;
$TOD = $_POST['TOD'] ;
$TOM = $_POST['TOM'] ;
$TOY = $_POST['TOY'] ;
if ($RoomsComboBox !== 'ALL') {
$room = " `Room` = '" . $RoomsComboBox . "'";
}
if ($FROMD !== '' AND $FROMM !== '' AND $FROMY !== '') {
$from = " `Checkout` >= '" . $FROMY . "-" . $FROMM . "-" . $FROMD . "'";
if ($TOD !== '' AND $TOM !== '' AND $TOY !== '') {
$to = " AND `Checkout` <= '" . $TOY . "-" . $TOM . "-" . $TOD . "'";
}
$between = $from . $to;
}
If ($between !== '' OR $room !== '') {
$query = $query . " WHERE" ;
}
If ($between !== '' AND $room !== '') {
$query = $query . $between . " AND" . $room;
}
If ($between !== '' AND $room == '') {
$query = $query . $between;
}
If ($between == '' AND $room !== '') {
$query = $query . $room;
}
$query = $query . " ORDER BY ID DESC";
//printf($query);
我做了什么: 来自
$query = "SELECT `ID`, `Desc` FROM `Rooms` ORDER BY `Desc` ASC" ;
到
$query = "SELECT `ID`, `Desc` FROM `Rooms` WHERE `Desc` = 'Frontoffice' OR `Desc` = 'Backoffice' OR `Desc` = 'Manager' ORDER BY `Desc` ASC" ;
来自
$query = "SELECT * FROM `Users`";
到
$query = "SELECT `ID`, `Desc` FROM `Rooms` WHERE `Desc` = 'Frontoffice' OR `Desc` = 'Backoffice' OR `Desc` = 'Manager' ORDER BY `Desc` ASC" ;
部分正在工作,我可以在组合框中看到只有办公室扩展,我可以搜索我是否从下拉列表中查看“全部”,但如果我选择其他东西例如Frontoffice并点击搜索页面正在重播一个错误。< / p>
日期搜索根本不起作用。 我必须建议你们,我不知道php和MySQL只是一些非常基础:) 有人可以用一些语法帮助我吗? 非常感谢。
在这里输入代码
答案 0 :(得分:0)
您的第一个查询可以简化:
Combine
第二个查询不会在何时以及如何执行时显示,而是$query = "SELECT `ID`, `Desc` FROM `Rooms` WHERE `Desc` IN ( 'Frontoffice', 'Backoffice', 'Manager') ORDER BY `Desc` ASC" ;
以及 NOT Users
的问题,所以哟不能使用同一条线。您需要分析表并进行调整。
答案 1 :(得分:0)
感谢。你说得对,这是我在第二次询问中的错误,我也尝试过:
$query = "SELECT * FROM `Users` WHERE `Desc` = 'Frontoffice' OR `Desc` = 'Backoffice' OR `Desc` = 'Manager' " ;
结果相同。我无法从结帐日期搜索,该网站显示查询错误。
答案 2 :(得分:0)
错误地我错过了代码的最后一部分。
$query = $query . " ORDER BY ID DESC";
//printf($query);
$result = mysql_query($query) or die("Web site query failed");
mysql_close($dbconnection);
while ($row = mysql_fetch_array($result)) {
echo "<TR><TD><FONT face=verdana,sans-serif>" . $row["ID"] . "</TD><TD>" . $row["Desc"] . "</TD><TD>" .$row["Name"] ."</TD><TD>" . $row["Checkin"] . "</TD><TD>" . $row["Checkout"] . "</TD><TD>" . $row["Total"] . "</TD><TD><a href=\"ec.php?Ext=" .$row["Ext"] . "&Checkin=" . $row["Checkin"] . "&Checkout=" . $row["Checkout"] ."\">".$SecLab29."</a></TD></TR>\n" ;
}
echo "</TABLE>\n";
endif;