Jump to content

[SOLVED] Tryin' a Little Trick


FlyingIsFun1217

Recommended Posts

Hey!

 

I'm trying to do an interesting page thing so that I can do multiple pages for listings. Here's my current code:

 

$pageNumber = $_GET['page'];
$parsedNumber = 1;

if($pageNumber == '')
{
	$pageNumber = 1;
}

foreach(glob('*.jpg') as $picFileJPG)
		{
			while((($pageNumber*20)-19)<= $parsedNumber && ($pageNumber*20)>= $parsedNumber)
			{
				$simplePicName = substr_replace($picFileJPG,'',-4);

				if($tableRowNumber == 1)
				{
					echo '<td>';
					echo '<table>';
				}

				echo '<tr>';
				echo '<td>';
				echo '<a href="'.$baseURL.'viewPic.php?pID='.$picFileJPG.'">'.$simplePicName.'</a>';
				echo '</td>';
				echo '</tr>';

				if($tableRowNumber == 10)
				{
					echo '</table>';
					echo '</td>';

					$tableRowNumber = 1;
				}

				else
				{
					$tableRowNumber++;
				}
			}

			$parsedNumber++;
		}

 

Now, I'm trying to get it to do the following:

 

On page 1:    List first 20 results (result 1-21)

On page 2:    List second 20 results (result 21-40)

On page 3:    List third 20 results (result 41-60)

 

But right now, it seems to be cycling through printing the first result OVER AND OVER AND OVER. What am I missing here? I'm incrementing $parsedResult every time...

 

FlyingIsFun1217

Link to comment
Share on other sites

Thats a previous variable; Here is the full source file:

 

<?php
include("header.php");
include("password.php");
include("baseURL.php");

$cookiePassword = $_COOKIE['pMD5'];
$pageNumber = $_GET['page'];
$parsedNumber = 1;

if($pageNumber == '')
{
	$pageNumber = 1;
}

if(!$cookiePassword)
{
	echo '<script type="text/javascript">';
	echo 'window.location = "'.$baseURL.'login.php"';
	echo '</script>';
}

if($cookiePassword != $encryptedPass)
{
	setcookie("pMD5", "", time()-1);

	echo '<script type="text/javascript">';
	echo 'window.location = "'.$baseURL.'error.php"';
	echo '</script>';
}

else
{
	// For tracking the number of rows that have been filled in any certain table
	$tableRowNumber = 1;

	echo '<center>';
	//=================================================================================================//
	echo '<table>';
	echo '<tr>';

		foreach(glob('*.jpg') as $picFileJPG)
		{
			while((($pageNumber*20)-19)<= $parsedNumber && ($pageNumber*20)>= $parsedNumber)
			{
				$simplePicName = substr_replace($picFileJPG,'',-4);

				if($tableRowNumber == 1)
				{
					echo '<td>';
					echo '<table>';
				}

				echo '<tr>';
				echo '<td>';
				echo '<a href="'.$baseURL.'viewPic.php?pID='.$picFileJPG.'">'.$simplePicName.'</a>';
				echo '</td>';
				echo '</tr>';

				if($tableRowNumber == 10)
				{
					echo '</table>';
					echo '</td>';

					$tableRowNumber = 1;
				}

				else
				{
					$tableRowNumber++;
				}
			}

			$parsedNumber++;
		}

	echo '</table>';
	echo '</td>';
	echo '</tr>';
	echo '</table>';
	//=====================================================================================================//
	echo '</center>';
}

include("footer.php");
?>

 

FlyingIsFun1217

Link to comment
Share on other sites

Ok, let me refine the parts of my problem. Once I add the following, it starts listing the same thing over and over:

 

$pageNumber = $_GET['page'];
$parsedNumber = 1;

if($pageNumber == '')
{
	$pageNumber = 1;
}

while((($pageNumber*20)-19)<= $parsedNumber && ($pageNumber*20)>= $parsedNumber)
			{
// Here's where it does stuff that you guys don't need to worry about, since it works
}

$parsedNumber++;

 

Do not worry about the rest of it; I've tested it, and I can guarantee that it works the way I want it to.

 

FlyingIsFun1217

 

Link to comment
Share on other sites

Shouldn't it be though? Lets say the user enters "site.php?page=2". In this case, it would never show anything, because it would never cycle up to the number needed to start echoing the results. Basically, it needs to increment every time it does a foreach loop.

 

Thanks!

FlyingIsFun1217

Link to comment
Share on other sites

The problem with that is: say $pageNumber = 1 and $parsedNumber = 1

neither of them change when they are in the while loop, so the condition is always true, so the loop never ends.

 

while((($pageNumber*20)-19)<= $parsedNumber && ($pageNumber*20)>= $parsedNumber)

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.