Jump to content

variable not successfully being passed through address bar


berilac

Recommended Posts

Hi everyone.

You should be able to view the problem here:

http://purpleart.110mb.com/php/browse.php

Im just setting up a faux website for a bit of learning so you can basically ignore the content...

This is the would-be gallery page(s). Ive got it so that page 1 now works and displays the correct images. However, when you click '2' or 'next', which passes "page=2" through the address bar the code does not respond accordingly.

This checks to see if page is null and sets as one if so, but should leave it as 2, etc if stated in the address bar...
if (empty($page)) /* check if $page variable is empty */
{
  $page = 1; /* if empty, set to page 1 */
}

but no matter what, it seems $page always=1

Sorry for the slight garbledness...(if that is a word), but if anyone could help I would be most grateful!

Thank you,

Michael
Link to comment
Share on other sites

if you wish to view the code as wole, it is as follows:

it currently echo's to page number before the first image and as you will see, it never alters from one...
[code]
<?

/* Load html backplate */
include ("../html/head.html");

// Get database connection
include 'db.php';

/* set number of results per page */
$limit = 2;

/* set query to retrieve images held in gallery */
$query_count = "SELECT * FROM gallery";

/* actually retrieve images held in gallery */
$result_count = mysql_query($query_count);

/* count number of images */
$totalrows = mysql_num_rows($result_count);


/* BEGIN ADDING IMAGES */

if (empty($page)) /* check if $page variable is empty */
{
  $page = 1; /* if empty, set to page 1 */
}
echo $page;

$limitvalue = $page * $limit - ($limit);  /* set first image to pull for the current page */

$query = "SELECT * FROM gallery LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error " . mysql_error());
// selects all necessary data from gallery
// shows error if one occurs
/* Tip: The MySQL LIMIT value syntax is as follows: 
  LIMIT $row_to_start_at, $how_many_rows_to_return 
*/

if (mysql_num_rows($result) == 0)
{
  echo "There are no images in the Gallery";
}

echo "<table>"; //start a table

/* The following WHILE returns a row of data to the $row array. Each time the loop restarts, the

next row of data is used. So, each pass of the loop returns a different row of data. */
while ($row = mysql_fetch_array($result))
{
  echo ("<tr>\n<td>");
  echo ("<img src=\"../" . $row["thumb_path"] . "\" alt=\"\">");
  echo "</td>\n<td>";
  echo ($row["title"]);
  echo "</td>\n</tr>";
}

echo "</table>";

/* add PREVIOUS link */
if ($page != 1)
{
  $pageprev = $page--;
  echo ("<a href=\"php/browse.php?page=$pageprev\">PREVIOUS" . $limit . "</a> ");
}
else
{
  echo ("PREVIOUS "); //if first page, PREVIOUS is not a link
}

/* display PAGE NUMBERS */
$numofpages = $totalrows / $limit;

for ($i = 1; $i <= $numofpages; $i++)
{
  if ($i == $page)
  {
    echo ($i . " ");
  }
  else
  {
    echo ("<a href=\"php/browse.php?page=$i\">$i</a> ");
  }
}

if (($totalrows % $limit) != 0) //% function returns a remainder
{
  if ($i == $page)
  {
    echo ($i . " ");
  }
  else
  {
    echo ("<a href=\"php/browse.php?page=$i\">$i</a> ");
  }
}

/* add NEXT link */
if (($totalrows - ($limit * $page)) > 0) //check if more pages are remaining
{
  $pagenext = ($page + 1);
  echo("<a href=\"php/browse.php?page=$pagenext\">NEXT " . $limit . "</a>");
}
else
{
  echo ("NEXT"); //if last page NEXT is not a link
}

mysql_free_result($result);
/* clears $result just in case */


/* close html neatly */
include ("../html/foot.html");

?>
[/code]
Link to comment
Share on other sites

thank you,

but does that mean for all iterations of $page in the code is should use $_GET? (with or without isset)...?
im slightly confused, sorry. i know this is fairly simple.

i just changed the if empty($page) statement to use !isset instead and got this error...im sure im just being simple.

Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-2, 2' at line 1

Cheers
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.