Jump to content

Reloading the page with updated query string values


enchance

Recommended Posts

I'm trying to build a small portfolio and instead of using several HTML pages I wanted to just use PHP. What I have is an array of each image's path (for the "src" attribute). I was thinking when I click "Next" (a text link) it increments the array and once it has reloaded itself it would simply look at the query string then display the new image.

 

I have some questions though:

1. What line do I use which will reload the page with the new incremented variables?

2. When the page reloads itself, will it automatically get the new image to load? I already placed $thisimage = $_GET['imagenumber'] at the very top so it updates the "src" attribute for the image.

 

Thanks in advance. Any help/suggestions would be great, especially with that reloading part.

Sounds like your on the right path.

 

1. What line do I use which will reload the page with the new incremented variables?

$thisimage = $_GET['imagenumber'] should be placed above the line where you display the image, as long as you have that, you should be good.

 

2. When the page reloads itself, will it automatically get the new image to load?

Yes, because it will know what array value to pull by taking it from the URL.

 

<?php

$images = array("1.jpg", "2.jpg", "3.gif");
$thisimage = (isset($_GET['imagenumber']) ? $_GET['imagenumber'] : 0;

echo "<img src='".$images[$thisimage]."'>";

?>

Well, are you wanting the page to reload without having to refresh the browser? If that is what your after, your going to need AJAX or JavaScript. If it doesn't matter if the page has to refresh, then the method I supplied should work fine.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.