Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
移动到下一个录制按钮的HTML/PHP语法_Php_Html - Fatal编程技术网

移动到下一个录制按钮的HTML/PHP语法

移动到下一个录制按钮的HTML/PHP语法,php,html,Php,Html,我正在一个HTML页面上开发一个“转到下一个记录”按钮 嗯,它进入下一个记录一次,然后停止。首次单击后单击“先前问题”按钮时,不会发生任何情况。因为我增加了发行号,所以光标应该移动到下一条记录。我目前只处理“先前问题”按钮 HTML语法: <a href="index.php?content=main_window&id=1" title="Show More Recent Issue" >&#60; Next (Newer) Issue</a> &

我正在一个HTML页面上开发一个“转到下一个记录”按钮

嗯,它进入下一个记录一次,然后停止。首次单击后单击“先前问题”按钮时,不会发生任何情况。因为我增加了发行号,所以光标应该移动到下一条记录。我目前只处理“先前问题”按钮

HTML语法:

<a href="index.php?content=main_window&id=1" title="Show More Recent Issue" >&#60; Next (Newer) Issue</a> &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp <a href="index.php?main_window&id=-1 title ="Show Older Issue" >Prior (Older)) Issue &#62;</a>

现在只处理“案例1”

switch(trim($cycle_direction)) 
        {
            case -1:
               // display an older issue
                echo "Decrement<br>";
                $current_record_number=$current_record_number +1;
                echo $current_record_number;
                mysqli_data_seek($result, 0);       
                mysqli_data_seek($result, $current_record_number);
                $row=mysqli_fetch_row($result); 
                printf ("%s \n",$row[0]);   
                $issuenum=$row[0];                      
                break;
            case 0:
                // display current issue
                //echo "No Selection";
                break;
            case 1:
                // display newer issue 
                //echo "Increase";
                $issuenum=2165;
                break;
        }   
开关(微调($cycle_direction))
{
案例1:
//显示旧问题
回声“减量
”; $current_record_number=$current_record_number+1; echo$当前\u记录\u编号; mysqli_data_seek($result,0); mysqli_data_seek($result,$current_record_number); $row=mysqli\u fetch\u行($result); printf(“%s\n”,$row[0]); $issuenum=$row[0]; 打破 案例0: //显示当前问题 //回应“无选择”; 打破 案例1: //显示较新的问题 //呼应“增加”; $issuenum=2165; 打破 }
更新 这是我从你的评论中得到的:

function return_row_number() {
 // Loop through the Array;  Get Row Number for the current issue global  $result,$issuenum, $rowcount; 
 $count =0; 
 mysqli_data_seek($result, 0); 
 while($row=mysqli_fetch_array($result, MYSQL_ASSOC)) { 
     ++$count; 
     if($issuenum == $row['IssueIDNUM']) { 
      return $count -1; break; 
     } 
   } 
 }
现在,神秘值是
$issuenum

还有一个术语问题。这不是“循环数组”,而是查询数据库并循环查询结果。

这是一种查找下一条记录的低效方法。但在更正之前,您需要解释
$issuenum
的值来自何处。

了解更多关于数据库表的信息也会有所帮助,尤其是:
有多少个问题记录?
什么是编号方案?
新问题多久添加一次?

更新结束


使用这行代码,您将始终获得值1

$current\u record\u number=$current\u record\u number+1;

因为
$current\u record\u number
=0


您应该将当前问题添加到
href
中,其中xx=当前记录。
我将“id”改为“cycle”
content=
添加到下一个
href

<a href="index.php?content=main_window&cycle=1&rec=xx" 

title="Show More Recent Issue" >    &#60; Next (Newer) Issue</a>
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp

<a href="index.php?content=main_window&cycle=-1&rec=xx

title ="Show Older Issue" >Prior (Older)) Issue &#62;</a>
和变化:

$cycle_direction = trim($_REQUEST['id']); 
致:


您只需使用
intval()

$cycle_direction = intval($_REQUEST['id']); 
也不是
$current\u record\u number=$current\u record\u number+1;

$cycle_direction = intval($_REQUEST['id']); 
您可以使用:
$current\u record\u number+=$cycle\u direction

并消除开关。


非常规方法

假设问题的值为1到10。

$next[-1] = array(0,10,1,2,3,4,5,6,7,8,9,1);
$next[1] = array(0,2,3,4,5,6,7,8,9,10,1);
$next[0] = array(0,1,2,3,4,5,6,7,8,9,10); 

$nextIssue = $next[intval($_REQUEST['id'])];
如果问题编号为2001年至2010年

$nextIssue = 2000 + $next[intval($_REQUEST['id'])];
无论您有多少问题,都不需要使用数据库。

如上所示创建$next数组,然后保存该数组

$fp = fopen('next.ser','w');
fwrite($fp,serialize($next));
fclose($fp);
在应用程序中需要$next数组时,请使用:

$next= unserialize(file_get_contents('next.ser'));

用正确的方法来做。你所需要的只是带有下一个/上一个记录ID的url

$current_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// in case you are using MySQL
$query = "SELECT 
    prev_id, next_id
FROM
    (SELECT 
        id AS prev_id
    FROM
        issues
    WHERE
        id < $current_id
    LIMIT 1) a,
    (SELECT 
        id AS next_id
    FROM
        issues
    WHERE
        id > $current_id
    LIMIT 1) b";

// fetch query data
$prev_id = ...
$next_id = ...

// SHOW CURRENT ISSUE

    echo '<a href="index.php?content=main_window&id='.$next_id.'" title="Show More Recent Issue" >&#60; Next (Newer) Issue</a> - <a href="index.php?main_window&id=$prev_id title ="Show Older Issue" >Prior (Older)) Issue &#62;</a>';
$current\u id=isset($\u GET['id'])?intval($\u GET['id']):0;
//如果您使用的是MySQL
$query=“选择
上一个id,下一个id
从…起
(选择
id作为上一个id
从…起
问题
哪里
id<$current\u id
限制1)a,
(选择
id作为下一个\u id
从…起
问题
哪里
id>$current\u id
限制1)b”;
//获取查询数据
$prev_id=。。。
$next_id=。。。
//显示当前问题
回声'-';
如果您从任何其他数据库获取数据,逻辑是相同的。只需选择上一个和下一个id,并使用$prev_id和$next_id提供URL

另一个解决方案使用最大/最小技巧

$query = "SELECT
        (SELECT MAX(id) FROM issues WHERE id < t.id) as prev_id,
        (SELECT MIN(id) FROM issues WHERE id > t.id) as next_id
FROM issues t WHERE t.id = $current_id";
$query=“选择
(从idt.id的问题中选择MIN(id)作为下一个\u id
来自问题t,其中t.id=$current_id”;
“Beta”版本现在可以运行了。我将代码精简到最基本的部分,并添加了许多echo语句来观察程序的响应。简短的回答是,PHP在每个网页之间没有内存,因此变量的值“丢失”。虽然我隐约意识到这一点,但它在一段时间内并没有变得明显

解决方案是开发几个$_会话变量来保存数组并监视光标的位置

 <?php
 // Start the session
 session_start();
 include ("establish_array.php");
 ?> 

下面的代码构成“build_array.php”以在“$\u SESSION['result']”中建立数组


下面的代码嵌入在case(switch)语句中,以便在按下伪“next”HTML键时将杂志问题移动到下一个较旧的杂志。函数“return_row_number();”返回当前行号,行号中添加+1,并使用“mysqli_data_seek”移动到下一个(较旧的)记录(问题)

$issuenum=$\u会话['issuenum'];
$\会话['cursor\u location']=返回行号();
回显“光标位置:.”会话['Cursor\u Location']。“
”; $会话['cursor\u location']=$会话['cursor\u location']+1; mysqli_data_seek($result,0); mysqli_data_seek($result,$_SESSION['cursor_location']); $row=mysqli\u fetch\u行($result); $issuenum=$row[0]; $\会话['issuenum']=$issuenum; 回显“发行编号:$issuenum
”;

感谢:误解、解围和Alexander Ravikovich提供了有用的建议和线索。

案例1被硬编码为一个问题编号。那么,嗯-你期待什么?我希望你在用户会话中或至少在cookie中保存$current\u record\u编号?如果没有,你会惊讶地发现PHP是无状态的……解围:谢谢你的帮助他回答。我将不得不更详细地检查它。正如y
$query = "SELECT
        (SELECT MAX(id) FROM issues WHERE id < t.id) as prev_id,
        (SELECT MIN(id) FROM issues WHERE id > t.id) as next_id
FROM issues t WHERE t.id = $current_id";
 <?php
 // Start the session
 session_start();
 include ("establish_array.php");
 ?> 
<?php   
 require_once 'php_data/login_data.php';
 $conn = new mysqli($hn, $un, $pw, $db);
 if ($conn->connect_error) die($conn->connect_error.'   Sorry,   could       not   connect to the sfmags database server'); 
 $query = "Select IssueIDNUM FROM tblIssueList ORDER by IssueDate DESC,   IssueIDNUM ";
 $_SESSION['result'] =$conn->query($query);  
 if (!$_SESSION['result']) die($conn->error);
 $_SESSION['rowcount'] = mysqli_num_rows($_SESSION['result']);
 ?> 
            $issuenum = $_SESSION['issuenum']; 
            $_SESSION['cursor_location'] = return_row_number();
            echo "Cursor Location :" . $_SESSION['cursor_location'] . "<br>";
            $_SESSION['cursor_location'] = $_SESSION['cursor_location'] + 1;
                mysqli_data_seek($result, 0);   
                mysqli_data_seek($result,$_SESSION['cursor_location']);                 
                $row=mysqli_fetch_row($result); 
                $issuenum=$row[0];
                $_SESSION['issuenum'] = $issuenum; 
                echo "Issue Number: $issuenum <br>";