(直接跳到 sentence_editor.php 代码部分的评论)
我正在设计一个程序的后端,允许管理员调整存储在数据库中的句子。
重复步骤4和5 ad nauseam 。
以下是与我的问题相关的所有代码,以便进一步澄清:
fetchSentences.php
<?php
$query = "SELECT * FROM sentences LIMIT 100";
$results = $conn->query($query) or die($conn->error.__LINE__);
while($row = $results->fetch_assoc()){
$ids[] = $row['id']; // stores the id of the retrieved sentence
}
?>
的index.php
<?php include 'fetchSentences.php'; ?>
<html>
<a href="sentence_editor.php?n=0" class="start">Start!</a>
</html>
sentence_editor.php
<?php
$n = $_GET['n']; // n represents the index of the ids[] array
$id = $ids[$n]; // gets the id of the next sentence to be edited. My problem lies in this line. I am referencing an array $ids[] which was declared in a different file (namely, fetchSentences.php).
// How can I reference $ids[] in this file???
// If I add "include 'fetchSentences.php'" this will end up executing the fetchSentences.php code all over again resulting in an entirely new array of sentence IDs.
/*
* code which fetches the sentence from the database
*/
?>
<html>
<form method="post" action="process_updateSentence.php?id=<?php echo $id?>&n=<?php echo $n?>">
process_updateSentence.php
<?php
header("Location: sentence_editor.php?n=" . ++$n);
?>