PHP change data on click - php

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:
<?php
if(isset($_GET('file'))) rename("/blank.txt", "/" . $_GET('file') . ".txt");
?>
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:
<?php
if(isset($_GET('file'))) {
$data=file("/" . $_GET('file') . ".txt");
foreach($data as $temp){
echo $temp;
}
}
?>
The header function could go to a dynamic page that pulls the filename with $_GET:
<?php
if(isset($_GET('file'))) header("Location: http://www.example.com/dynamic?page=" . $_GET('file'));
?>
And that page could run the foreach loop.

Related

php dynamically creating a file on form submit

would any one know how to automatically create a file through PHP so when the tag is clicked it also have the file right now it's only a path which is displayed through a loop. but when you click it there is no file, of course, long story short how can I also create a file too with a loop so all links have files created through fopen or something, just like all of them have paths generated.
<?php
function display_user_docs($doc_array) {
// set global variable, to test later if this is on the page
global $doc_table;
$doc_table = true;
?>
<br>
<form name="doc_table" action="delete_doc.php" method="post">
<table width="300" cellpadding="2" cellspacing="0">
<?php
$color = "#cccccc";
echo "<tr bgcolor=\"".$color."\"><td><strong>Documentations</strong></td>";
echo "<td><strong>Delete?</strong></td></tr>";
if ((is_array($doc_array)) && (count($doc_array) > 0)) {
foreach ($doc_array as $doc) {
if ($color == "#cccccc") {
$color = "#ffffff";
} else {
$color = "#cccccc";
}
echo "<tr bgcolor=\"".$color."\"><td><a class=\"all-doc-link\" href=\"".$doc.".php\">".htmlspecialchars($doc)."</a></td>
<td><input type=\"checkbox\" name=\"del_me[]\"
value=\"".$doc."\"></td>
</tr>";
}
} else {
echo "<tr><td>No documentation on record</td></tr>";
}
?>
</table>
</form>
<?php
}
?>
You can use file_put_contents to create a file in PHP.
It takes two parameters, the first of which is the name of the file to create, and the second of which is the contents to put inside of the file.
For example, if I wanted to make a file called 123.txt which contains hello world, I would do the following:
file_put_contents("123.txt", "hello world");
The filename can contain slashes /, so that you can specify which folder to create the file in. Thus, if I wanted to make my 123.txt file in the folder abc, I can put abc/123.txt as the filename (as long as abc is in the same folder as the PHP script).
You can find more about file_put_contents in the PHP manual.

Wordpress: How Can You Get The URL Of The Next Child Page In A Sequence Of Child Pages

I'm finishing up my new portfolio and am trying to figure out a way to get a 'next' and 'prev' URLs for the child pages of the parent, which is called 'Work'.
The reason I want URLs is because the actual clickable link is an SVG at larger viewport sizes and I want to maintain all of my css access to the SVGs.
I'm including an image of how the navigation looks (looks like an aside, but it's actually a outside of the ).
I know that pages in worpress 'aren't meant to be paginated' but this is the same thing as creating a new post type and using the pagination there, except im doing some other things where I want access to templates. I tried using this plugin:
http://binarym.com/2009/next-page-not-next-post/
Which works, but I can't get my SVGs in there as opposed to text. If anyone has a way to replace the text in those strings with my SVG paths, that's an acceptable fix too. Here's a code snippet of what that looks like using that plugin:
<nav role="navigation" class="project-pagination">
<a href="/work">
<?php include (TEMPLATEPATH . '/images/_svgs/nav_gallery.svg'); ?>
</a>
<?php
$nextPage = next_page_not_post('Next Page', 'true', 'sort_column=post_date&sort_order=desc');
$prevPage = previous_page_not_post('Previous Page', 'true', 'sort_column=post_date&sort_order=desc');
if (!empty($nextPage) || !empty($prevPage)) {
if (!empty($nextPage)) echo $nextPage;
if (!empty($prevPage)) echo $prevPage;
}
?>
</nav>
Thanks all!
I found the answer here: Magic Town
<nav role="navigation" class="project-pagination">
<a href="/work" aria-label="View All Projects" alt="View All Projects">
<?php include (TEMPLATEPATH . '/images/_svgs/nav_gallery.svg'); ?><span>View All Projects</span>
</a>
<?php
$pagelist = get_pages("child_of=".$post->post_parent."&parent=".$post->post_parent."&sort_column=menu_order&sort_order=asc");
$pages = array();
foreach ($pagelist as $page) {
$pages[] += $page->ID;
}
$current = array_search($post->ID, $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<?php if (!empty($nextID)) { ?>
<?php include (TEMPLATEPATH . '/images/_svgs/nav_next.svg'); ?><span>Next Project</span>
<?php }
if (!empty($prevID)) { ?>
<?php include (TEMPLATEPATH . '/images/_svgs/nav_prev.svg'); ?><span>Previous Project</span>
<?php } ?>

Colorbox opens document outside box

I'm using Colorbox for my PM system. Clickin on the 'Inbox' link, opens colorbox and loads the inboxpage via ajax. The inboxpage shows linked titles of the users messages. Clickin on that, should open the read_message page inside the same colorbox. Unfortunately, that is not the case. Whenever I click on the link, it just opens the page outside the box.
I've tried different things, but no love whatsoever. Any help would be appreciated!
Piece of javascript (If you need the whole javascript of Colorbox.js, please let me know so!)
$(document).ready(function(){
$("#ajax").colorbox({ajax:true, width:"500px", height:"450px"});
});
Page that opens the Colorbox once $newMessages or $noNewMessages has been clicked
<div class="pageHeader">
<p class="title"><?php echo $myAccount ?></p>
<a class="viewMessages" id="ajax" href="message/inbox.php">
<?php
if (mysqli_num_rows($getAmountMessages) > 0 ) {
$row = mysqli_fetch_array($getAmountMessages);
if($row['message_read'] == 0){
echo $newMessages;
} else {
echo $noNewMessages;
}
}
?>
</a>
</div>
Inbox page - Clickin on the Linked Titles should open the read_message.php file within the Colorbox
//Select messages in db
$getMessages = mysqli_query($mysqli,"SELECT * FROM messages WHERE recipient = '".$_SESSION['user_id']."' ORDER BY message_id DESC");
$numMessages = mysqli_num_rows($getMessages);
//Message(s) available for user
if (mysqli_num_rows($getMessages) > 0 ) {
echo '<ul>';
for($count = 1; $count <= $numMessages; $count++)
{
$row = mysqli_fetch_array($getMessages);
//Show if a message is still new
if($row['message_read'] == 0)
{
echo '<a id="ajax" href="message/read_message.php?messageid='.$row['message_id'].'">'.$row['message_title'].'</a>(NEW MESSAGE)<br>';
}else{
echo '<a id="ajax" href="message/read_message.php?messageid='.$row['message_id'].'">'.$row['message_title'].'</a><br>';
}
}
echo '</ul>';
//No message(s) available for user
}else{
echo ("<p class='messagesinfo'>Er zijn geen nieuwe berichten</p>");
}
Thank you.
When clicking on a message (link), you are telling the browser to do a redirect to that link, which will result in a new page load.
Instead, you need to call $.colorbox via javascript.
Change your links from:
<a id="ajax" href="message/read_message.php?messageid='.$row['message_id'].'">'.$row['message_title'].'</a>
to
<a id="ajax" onclick="showMessage($row['message_id'])">'.$row['message_title'].'</a>
In your Javascript add the following function:
function showMessage(id) {
$.colorbox({href:"message/read_message.php?messageid=" + id});
}
Hope this helps!

PHP link to include header

I have php reading a text file that contains all the names of images in a directory, it then strips the file extension and displays the file name without the .jpg extension as a link to let the user click on then name, what I am looking for is a easy way to have the link that is clicked be transferred to a variable or find a easier solution so the link once it is clicks opens a page that contains the default header and the image they selected without making hundreds of HTML files for each image in the directory.
my code is below I am a newbie at PHP so forgive my lack of knowledge.
thank you in advance. also I would like a apple device to read this so I want to say away from java script.
<html>
<head>
<title>Pictures</title>
</head>
<body>
<p>
<?php
// create an array to set page-level variables
$page = array();
$page['title'] = ' PHP';
/* once the file is imported, the variables set above will become available to it */
// include the page header
include('header.php');
?>
<center>
<?php
// loads page links
$x="0";
// readfile
// set file to read
$file = '\filelist.txt' or die('Could not open file!');
// read file into array
$data = file($file) or die('Could not read file!');
// loop through array and print each line
foreach ($data as $line) {
$page[$x]=$line;
$x++;
}
$x--;
for ($i = 0; $i <= $x; $i++)
{
$str=strlen($page[$i]);
$str=bcsub($str,6);
$strr=substr($page[$i],0,$str);
$link[$i]= "<a href=".$page[$i]."jpg>".$strr."</a>";
echo "<td>".$link[$i]."<br/";
}
?>
</P></center>
<?php
// include the page footer
include('/footer.php');
?>
</body>
</html>
add the filename to the url that you want to use as a landing page, and catch it using $_GET to build the link.
<a href='landingpage.php?file=<?php echo $filename; ?>'><?php echo $filename; ?></a>
Then for the image link on the landing page
<img src='path/to/file/<?php echo $_GET['file'] ?>.jpg' />

Fail to using if/else to hover image by dynamic url

I'm using the basic way to doing the hover image as the CSS method doesn't work for me. Current I'm using the if/else statement to do so. If the contain the URL like abc.com it will hover the image.
But now I only can hover the group url but if there is sub categories in groups I won't able to hover, how can I do it all the activity inside the group, the image will hover?
How to doing if the URL contain the words or path. For example abc.com/groups/* it will hover the groups. Similar like we doing searching in MySQL the words/variable as using "%".
<?php
$request_url = apache_getenv("HTTP_HOST") . apache_getenv("REQUEST_URI");
$e = 'abc.com/dev/';
$f = 'abc.com/dev/groups/';
$g = 'abc.com/dev/user/';
?>
<div class="submenu">
<?php
if ($request_url == $e) {
echo '<div class="icon-home active"></div>';
} else {
echo '<div class = "icon-home"></div>';
}
?>
<?php
if ($request_url == $f) {
echo '<div class="icon-groups active"></div>';
} else {
echo '<div class = "icon-groups"></div>';
}
?>
</div>
I propose a javascript way to do so, with jQuery
$("a[href*='THE_URL_PATTERN_YOU_WANT_TO_MATCH']").children(".icon-home").addClass("active");
BTW, it is NOT a good idea to wrap a div into a a tag.

Categories