Jump to content

Recommended Posts

how can this work

<?php
// how many rows to show per page
$rowsPerPage = 1;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

$query  = "SELECT image_link, image_name, image_id, image_caption FROM hayleyimages LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');


// print the random numbers
while(list($val) = mysql_fetch_array($result))
{
echo "$val";
?>
<table id="portfolio_image">
<tr><th><?php echo .$val['image_name'].; ?></th></tr><tr><td><?php echo '<a href="'.$val['image_link'].'" rel="lightbox" title="'.$val['image_caption']. '" ><img src="'.$val['image_link'].'"width="200px" /></a>'; ?></td><td width="200px"><?php echo 'Image ID :'.$val['image_id'].''; ?></td></tr><tr><td><?php echo ' '.$val['image_caption']. ' </a>'; ?></td></tr><tr><td><a href="portfolio.php">Return To Gallery</a></td></tr></table><br>
<?php
}

echo '<br>';

// how many rows we have in database
$query   = "SELECT COUNT(image_id) AS numrows FROM hayleyimages";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

$self = $_SERVER['PHP_SELF'];

// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link

// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";

$first = " <a href=\"$self?page=1\">[First Page]</a> ";
} 
else
{
$prev  = ' [Prev] ';       // we're on page one, don't enable 'previous' link
$first = ' [First Page] '; // nor 'first page' link
}

// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";

$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
} 
else
{
$next = ' [Next] ';      // we're on the last page, don't enable 'next' link
$last = ' [Last Page] '; // nor 'last page' link
}

// print the page navigation link
echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong>" . $next . $last;

?>

 

this bit inparticular

<?php
$query  = "SELECT image_link, image_name, image_id, image_caption FROM hayleyimages LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');


// print the random numbers
while(list($val) = mysql_fetch_array($result))
{
echo "$val";
?>
<table id="portfolio_image">
<tr><th><?php echo .$val['image_name'].; ?></th></tr><tr><td><?php echo '<a href="'.$val['image_link'].'" rel="lightbox" title="'.$val['image_caption']. '" ><img src="'.$val['image_link'].'"width="200px" /></a>'; ?></td><td width="200px"><?php echo 'Image ID :'.$val['image_id'].''; ?></td></tr><tr><td><?php echo ' '.$val['image_caption']. ' </a>'; ?></td></tr><tr><td><a href="portfolio.php">Return To Gallery</a></td></tr></table><br>
<?php
}

 

it echoes the letter

i

but i know that the database has information and that it is connected and that all the words are right(i think), a similar code is working on my site, and i need to add pagination to it.

 

I've found out that the

i

is the first letter of the image_link

Link to comment
https://forums.phpfreaks.com/topic/104966-does-anyone-know-how/
Share on other sites

not sure if this fixes it. I just cleaned up a couple syntax errors:

<?php
$query  = "SELECT image_link, image_name, image_id, image_caption FROM hayleyimages LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');


// print the random numbers
while(list($val) = mysql_fetch_array($result))
{
echo "$val";
?>
<table id="portfolio_image">
<tr><th><?php echo $val['image_name']; ?></th></tr><tr><td><?php echo '<a href="'.$val['image_link'].'" rel="lightbox" title="'.$val['image_caption']. '" ><img src="'.$val['image_link'].'"width="200px" /></a>'; ?></td><td width="200px"><?php echo 'Image ID :'.$val['image_id'].''; ?></td></tr><tr><td><?php echo ' '.$val['image_caption']. ' </a>'; ?></td></tr><tr><td><a href="portfolio.php">Return To Gallery</a></td></tr></table><br>
<?php
}

Link to comment
https://forums.phpfreaks.com/topic/104966-does-anyone-know-how/#findComment-537305
Share on other sites

it still only echoes the first letter of the word,

 

what i am trying to do is paginate this

<?php 
require_once 'header.php';
$pageid = "2";
$sq1 = "SELECT * FROM hayleyedit WHERE page_id ='{$pageid}' LIMIT 0,1;";
$result1 = mysql_query($sq1) or die("Error:" . mysql_error());
$rom = mysql_fetch_assoc($result1);
$content_port = $rom['content'];
if (isset($_GET['image_id']))
{
if ((int) $_GET['image_id'] > 0) 
{

$imageid = $_GET['image_id'];
$sql = "SELECT * FROM hayleyimages WHERE image_id=$imageid";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$imageprofname = $row['image_name'];
$imageprofcaption = $row['image_caption'];
$imageproflink = $row['image_link'];
if(mysql_num_rows($result) > 0)
{
?>
<div id="prof_img">
	<table id="portfolio_image">
<tr><th><?php echo "$imageprofname"; ?></th></tr><tr><td><?php echo '<a href="'.$row['image_link'].'" rel="lightbox" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="200px" /></a>'; ?></td><td width="200px"><?php echo 'Image ID :'.$row['image_id'].''; ?></td></tr><tr><td><?php echo ' '.$row['image_caption']. ' </a>'; ?></td></tr><tr><td><a href="portfolio.php">Return To Gallery</a></td></tr></table></div>
<?php
}
	if (mysql_num_rows($result) < 1) {
		 echo 'This ID does not exist in the database<br>';
		 echo "<a href=\"index.php\">Return to Image Page</a>";
		 exit();
	}
exit();
}
	else {
	 echo "Unknown Image ID! <br />";
	 echo "<a href=\"index.php\">Return to Image Page</a>";
	 exit();
	}
}
//No ID passed to page, display user list:
$query = "SELECT image_id, image_name, image_link, image_caption FROM `hayleyimages`";
$result = mysql_query($query) or die("Error:" . mysql_error());

if (mysql_num_rows($result) > 0) {
?>
<table class="welcome_port"><tr><td><?php echo"$content_port"; ?>
<?php
if ($_SESSION['logged_in'] == true) 
{
?>
<td><a href="live_edit.php?editpageid=<?php echo $_SESSION['page_name'] ?>">Edit</a></td></tr></table>
<?php
}
else
{
?>
</td></tr></table>
<?php
}
?>
<table id="portfolio">
<?php
               $loop = 3;
		   $loop1 = 3;
	while($row=mysql_fetch_array($result)){ // Start looping table row

	if ($loop == 3) {
                        echo "<tr>";
                }
	$toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td>    </td>';
	$toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td>    </td>';

                
                if ($loop == 3) 
			{
                        echo "</tr>";
                        $loop=0;
                }   


	}
               if (substr($toecho, -5) != "</tr>") {
                  $toecho .= "</tr>";
               }
               echo $toecho;
               echo $toecho1;
}

?>		
</table>
<?php
		if (mysql_num_rows($result) < 1) {
		echo "No Images To Display";
		}
?>
</div>
<?php
require_once 'footer.php';
?>

Link to comment
https://forums.phpfreaks.com/topic/104966-does-anyone-know-how/#findComment-537311
Share on other sites

well, I'm not sure what some of your code does, because it makes no sense. in one of your while loops, you don't increment a number that you use for counting. I'm not sure if that's by accident, or design.  I cleaned up the code so if someone else wants to help, it will be easier to follow:

<?php 
require_once 'header.php';
$pageid = "2";
$sq1 = "SELECT * FROM hayleyedit WHERE page_id ='{$pageid}' LIMIT 0,1;";
$result1 = mysql_query($sq1) or die("Error:" . mysql_error());
$rom = mysql_fetch_assoc($result1);
$content_port = $rom['content'];
if (isset($_GET['image_id']))
{
if ((int) $_GET['image_id'] > 0) 
{

$imageid = $_GET['image_id'];
$sql = "SELECT * FROM hayleyimages WHERE image_id=$imageid";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$imageprofname = $row['image_name'];
$imageprofcaption = $row['image_caption'];
$imageproflink = $row['image_link'];
$imageprotitle = $row['image_caption'];
$imageproid = $row['image_id'];
if(mysql_num_rows($result) > 0)
{
echo <<<END
<div id="prof_img">
<table id="portfolio_image">
	<tr>
		<th>$imageprofname</th>
	</tr>
	<tr>
		<td><a href="$imageproflink rel="lightbox" title=$imageprotitle" ><img src="$imageproflink" width="200px" /></a></td>
		<td width="200px">Image ID :$imageproid</td>
	</tr>
	<tr>
		<td>$imageprofcaption</a></td>
	</tr>
	<tr>
		<td><a href="portfolio.php">Return To Gallery</a></td>
	</tr>
</table>
</div>
END;
}
	if (mysql_num_rows($result) < 1) {
		echo <<<END
		 This ID does not exist in the database<br>
		 <a href="index.php">Return to Image Page</a>

END;
exit();
	}
exit();
}
	else {
		echo <<<END
	 Unknown Image ID! <br />
	 <a href="index.php">Return to Image Page</a>
END;
	 exit();
	}
}
//No ID passed to page, display user list:
$query = "SELECT image_id, image_name, image_link, image_caption FROM `hayleyimages`";
$result = mysql_query($query) or die("Error:" . mysql_error());

if (mysql_num_rows($result) > 0) {
?>
<table class="welcome_port"><tr><td><?php echo"$content_port"; ?>
<?php
if ($_SESSION['logged_in'] == true) 
{
$page_name = $_SESSION['page_name'];
echo <<<END
	<td><a href="live_edit.php?editpageid=$page_name">Edit</a></td>
</tr>
</table>
END;
}
else
{
print "</td></tr></table>";
}
print "<table id='portfolio'>";
               $loop = 3;
		   $loop1 = 3;
		   $toecho = "";
		   $toecho1 = "";
	while($row=mysql_fetch_array($result)){ // Start looping table row

	if ($loop == 3) {
                        echo "<tr>";
                }
	$toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td>    </td>';
	$toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td>    </td>';

                
                if ($loop == 3) 
			{
                        echo "</tr>";
                        $loop=0;
                }   


	}
               if (substr($toecho, -5) != "</tr>") {
                  $toecho .= "</tr>";
               }
               echo $toecho;
               echo $toecho1;
}

?>		
</table>
<?php
		if (mysql_num_rows($result) < 1) {
		echo "No Images To Display";
		}
?>
</div>
<?php
require_once 'footer.php';
?>

 

I know what you're doing, but I'm not sure why you are doing it this way.  maybe you could explain this bit:

<?php
               $loop = 3;
		   $loop1 = 3;
		   $toecho = "";
		   $toecho1 = "";
	while($row=mysql_fetch_array($result)){ // Start looping table row

	if ($loop == 3) {
                        echo "<tr>";
                }
	$toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td>    </td>';
	$toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td>    </td>';

                
                if ($loop == 3) 
			{
                        echo "</tr>";
                        $loop=0;
                }   


	}
               if (substr($toecho, -5) != "</tr>") {
                  $toecho .= "</tr>";
               }
[code]
this is the part that doesn't make sense to me.

[/code]

Link to comment
https://forums.phpfreaks.com/topic/104966-does-anyone-know-how/#findComment-537327
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.