PHP 点击时更改数据
我有一个 php 页面,它从两个 .txt 文件(一个用于信息,一个用于幻灯片图像)创建页面数据,并根据该数据创建分页。不过,我有几个不同的类别 - 所以我不希望所有的工作共享相同的分页。我希望用户能够从菜单中选择不同的类别,并且页面数据 txt 文件将会更改。
我想知道是否有一个脚本可以在单击菜单中的链接时简单地更改 .txts 文件的名称,然后转到该文件的第一页?
这是我当前的设置,在文档的开头:
<?php
$data=file("brief.txt");
$pages=0;
foreach($data as $temp){
$x=explode("|",$temp);
if($x[0]>0){
$pages=$pages+1;
}
}
if($_GET['p']){
$page=$_GET['p'];
}
if($_GET['i']){
$index=$_GET['i'];
}
if($index == "p"){
$page=$page-1;
}
if($index == "n"){
$page=$page+1;
}
if($page < 1){
$page=1;
}
if($page > $pages){
$page=$pages;
}
$line=$data[$page-1];
$fields=explode("|",$line);
?>
幻灯片图像(来自 work.txt)
<?php
echo"
<div id='portfolioslider'>
<div class='slider'>
";
$photos=file("work.txt");
foreach($photos as $image){
$item=explode("|",$image);
if($item[0]==$fields[0]){
$photo=trim($item[1]);
echo"<div><img src='images/work/$photo' alt='' /></div>\n";
}
}
echo"
</div>
</div>
"?>
信息(来自 Brief.txt)
<?php
echo"
<div id='overview'>
<h3>{$fields[1]}</h3> </br></br>
<h3>Project Overview:</h3> {$fields[2]}</div>";
echo"
<div id='skills'><h3>Skills:</h3><ul>{$fields[3]}</ul></div>
";
?>
I have a php page that creates page data from two .txt files (one for info, and one for slideshow images), and creates pagination based on this data. I have a few different categories though - so I don't want all the work sharing the same pagination. I would like the user to be able to select different categories from a menu, and the page data txt files will change.
I was wondering if there is a script which can simply change the name of the .txts file when a link in the menu is clicked, and go to the first page of that?
Here is my current setup, at start of document:
<?php
$data=file("brief.txt");
$pages=0;
foreach($data as $temp){
$x=explode("|",$temp);
if($x[0]>0){
$pages=$pages+1;
}
}
if($_GET['p']){
$page=$_GET['p'];
}
if($_GET['i']){
$index=$_GET['i'];
}
if($index == "p"){
$page=$page-1;
}
if($index == "n"){
$page=$page+1;
}
if($page < 1){
$page=1;
}
if($page > $pages){
$page=$pages;
}
$line=$data[$page-1];
$fields=explode("|",$line);
?>
Slideshow images (from work.txt)
<?php
echo"
<div id='portfolioslider'>
<div class='slider'>
";
$photos=file("work.txt");
foreach($photos as $image){
$item=explode("|",$image);
if($item[0]==$fields[0]){
$photo=trim($item[1]);
echo"<div><img src='images/work/$photo' alt='' /></div>\n";
}
}
echo"
</div>
</div>
"?>
Information (from brief.txt)
<?php
echo"
<div id='overview'>
<h3>{$fields[1]}</h3> </br></br>
<h3>Project Overview:</h3> {$fields[2]}</div>";
echo"
<div id='skills'><h3>Skills:</h3><ul>{$fields[3]}</ul></div>
";
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否完全理解您要问的内容,但是要在单击时重命名,您可以使用如下所示的 html:
然后在 page.php 上,有一个重命名 txt 文件的脚本:
然后转到该页面,我猜你可以有一个标头函数来转到另一个页面,或者你可以打开 page.php 上的 txt 文件:
标头函数可以转到一个动态页面,该页面使用 $_GET 提取文件名:
并且该页面可以运行foreach 循环。
I'm not sure if I understand exactly what you're asking, but to rename on a click, you could have html like so:
Then on page.php, have a script that renames the txt file:
Then to go to that page, I guess you could have a header function to go to another page, or you could just open the txt file on page.php:
The header function could go to a dynamic page that pulls the filename with $_GET:
And that page could run the foreach loop.