I m在项目上工作,I m 处理这一问题: 我有一个称为“类别”的变量,如果该类别无效或空洞,则将定为1类。 提交表格后,即第++类。 2. Okay,但第三人认为,它没有达到3。 我检查了发生的情况,我发现,每提交一次报告之后,美元就变成了1美元,因为第1条编码行文说,如果它无效或空洞,就会变成1美元。 1. 请允许我向各位展示一下我所说的话! 事先感谢你帮助!
session_start();
include_once( db.php );
$cat_SQL = SELECT * FROM categories ORDER BY id ;
$cat_RESULT = mysql_query($cat_SQL, $conn);
$cat_ROWS = mysql_fetch_assoc($cat_RESULT);
$cat_ROWS_number = mysql_num_rows($cat_RESULT);
if (is_null($category) || empty($category)) {
$category = 1;
}
if (isset($category)) {
if ($category < $cat_ROWS_number) {
$category = $category + 1; echo $category;
}
}
因此,如果我每次重复页数,我就这样:
First time you enter the page: category is empty so it becomes 1 => $category = 1 After 1st SUBMIT $category = $category + 1 => $category = 2 After 2nd SUBMIT $category = $category + 1 => $category = 2 (still 2 instead of becoming 3) and so on... :( HOW CAN I STOP $category from become 1 each time the page reloads / submits, and become the new value instead (per session)?
因此,我最终在看到你的答复之前就设法这样做(不是包罗万象,而是高兴地看到我亲眼看到答案:) iii
if (!isset($_SESSION[ category ])) {
$_SESSION[ category ] = 1;
$category = $_SESSION[ category ];
}
else {
if($_SESSION[ category ] < $cat_ROWS_number) {
$_SESSION[ category ]++;
$category = $_SESSION[ category ];
}
}
然而,感谢大家的迅速答复!