mysql> SELECT * FROM main_table;
+--------+----------+--------+
| id_book | id_author |description |
+--------+----------+--------+
| 1 | 101 | I love cat |
+--------+----------+--------+
mysql> SELECT * FROM author;
+---------+-----------+
| id_author | name_author |
+---------+-----------+
| 101 | Dr Sent |
+---------+-----------+
mysql> SELECT * FROM book;
+--------+---------+
| id_book | name_book |
+--------+---------+
| 1 | cat |
+--------+---------+
你好,我还是 PHP 的新手,现在我对 PHP 和 MySQL 有点困惑。我有一个与我在数据库中的一个表相关的下拉列表。
首先我的系统出现一个列表作者姓名的页面,用户将能够选择哪个用户喜欢。
JK ROWLING
DR SEUSS <-- author_name
ROAD DAHL
接下来,它将转到一个新页面并有一个选择(列表/菜单),其中显示了一个书名列表。我可以从数据库中检索下拉列表,但我的问题是当我在下拉列表中选择一本书名称时,它会显示所有书籍描述并且无法选择正确的描述。
这是我的编码,以使其更清晰
$currentPage = $_SERVER["PHP_SELF"];
mysql_select_db($database_config, $config);
$query_Recordset1 = "SELECT * FROM book ORDER BY name_book ASC";
$Recordset1 = mysql_query($query_Recordset1, $config) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$maxRows_Recordset2 = 1;
$pageNum_Recordset2 = 0;
if (isset($_GET['pageNum_Recordset2'])) {
$pageNum_Recordset2 = $_GET['pageNum_Recordset2'];
}
$startRow_Recordset2 = $pageNum_Recordset2 * $maxRows_Recordset2;
$colname_Recordset2 = "-1";
if (isset($_GET['id_book'])) {
$colname_Recordset2 = $_GET['id_book'];
}
mysql_select_db($database_config, $config);
$query_Recordset2 = sprintf("SELECT * FROM main_table WHERE id_book = %s ORDER BY description ASC", GetSQLValueString($colname_Recordset2, "int"));
$query_limit_Recordset2 = sprintf("%s LIMIT %d, %d", $query_Recordset2, $startRow_Recordset2, $maxRows_Recordset2);
$Recordset2 = mysql_query($query_limit_Recordset2, $config) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
if (isset($_GET['totalRows_Recordset2'])) {
$totalRows_Recordset2 = $_GET['totalRows_Recordset2'];
} else {
$all_Recordset2 = mysql_query($query_Recordset2);
$totalRows_Recordset2 = mysql_num_rows($all_Recordset2);
}
$totalPages_Recordset2 = ceil($totalRows_Recordset2/$maxRows_Recordset2)-1;
$queryString_Recordset2 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset2") == false &&
stristr($param, "totalRows_Recordset2") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset2 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset2 = sprintf("&totalRows_Recordset2=%d%s", $totalRows_Recordset2, $queryString_Recordset2);