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>
";
?>
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.