0

image_gallery.php

<?php
$i = 0;
//while ($data = mysql_fetch_object($result)){
for ($rows = 1; $rows<=3; $rows++){
echo "<tr>";
for ($cols=1; $cols<=4;$cols++){
if ($i >= $numRows) break;
echo '<td style="text-align:center;">';
						$data = mysql_fetch_object($result);
							echo '<div style="width:100px;font-family: verdana; font-size: 11px;">',$data->title;
							echo '<a href="'.$data->path.'" rel="lightbox[roadtrip]">';
							echo '	<span style="border:0px;"><img border="0px" class="reflect" src="'.$data->path.'" width="100" height="100" alt="'.$data->title.'" /></span>';
							echo '</a></div>';							
						echo "</td>";
						$i++;
					}
					echo "</tr>";
				}
			//}
			?>
			<tr>
				<td colspan="4" style="text-align:center;">
<?php
if ($totalpaging > 0){
//Write first and prev navigation
if ($paging > 1){
prevpaging = 0;
echo '<a style="text-decoration:none;" href="?page=image_gallery&paging=1"><<< First</a> ';
						}else{
							echo "<<< First ";
						}
						
						if ($paging > 1){
						
$prevpaging = $paging-1;
						
echo '<a style="text-decoration:none;" href="?page=image_gallery&paging='.$prevpaging.'"><< Prev</a> ...';
						}else{
							echo "<< Prev ";
						}

						//write number navigation
if ($paging > 1){
					
$beforepaging = $paging -1 ;
						
echo '<a style="text-decoration:none;" href="?page=image_gallery&paging='.$beforepaging.'">'.$beforepaging.'</a> ';
						}
						if ($paging != 0)	echo $paging;
						
						if ($paging < $totalpaging && $paging != 0){
							$nextpaging = $paging + 1 ;
							echo ' <a style="text-decoration:none;" href="?page=image_gallery&paging='.$nextpaging.'">'.$nextpaging.'</a>';
}
						
						//write next and last navigation
						if ($paging < $totalpaging){
							$nextpaging = $paging + 1;
							echo '...<a style="text-decoration:none;" href="?page=image_gallery&paging='.$nextpaging.'">Next >></a>';
						}else{
							echo " Next >>";
						}
						
						$pagingDiff = $totalpaging - ($paging - 1);				
						if ($pagingDiff > 1){					
							echo ' <a style="text-decoration:none;" href="?page=image_gallery&paging='.$totalpaging.'">Last >>></a>';
						}else{
							echo " Last >>>";
						}
					}
					?>
				</td>
			</tr>
		</table>

Next paging does not work! there is no error message it's just there suppose to be too many pictures to fit in a page, I wonder why the next page does not show up, I also unable to click next!

Edited by davy_yg: n/a

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by davy_yg
0

Sorry davy, your indenting is really messed up, making it really difficult to follow. Any chance you can reformat?

0

image_gallery.php

<?php
		
include('includes/koneksi.php');
	
$imgDt = isset($_POST['imgDt']) ? $_POST['imgDt'] : '';	
		
//Save File
if (isset($_REQUEST['save'])){
if (empty($_FILES['uploaded_file'])){
		echo "Tidak ada file yang diupload.";
}else{
	$title = mysql_real_escape_string($_REQUEST['title']);
	//$uploadPath = uploadPicture("uploaded_file");
	 $uploadPath = $_FILES['uploaded_file'];
			
	$sqlstr = "INSERT INTO image_gallery(title, path) ";
	$sqlstr .= "VALUES('".$title."','".$uploadPath."')";
	
	$result = mysql_query($sqlstr) or die(mysql_error());
			
	$confirmation = ($result)? "Gambar telah tersimpan." : "Gagal menyimpan data.";
	}
}
	
$limit = 25;
	
//Get total records
$resTotal = mysql_query("SELECT COUNT(id) AS total FROM image_gallery") or die(mysql_error());
$data = mysql_fetch_object($resTotal);
$totalRec = $data->total;
	
//Get total pages
$totalpaging = ceil($totalRec / $limit);
		
$paging = (!empty($_REQUEST['paging']) && $_REQUEST['paging'] != 0)? $_REQUEST['paging'] : 1 ;
	
//Set record position
if (empty($paging) || $paging ==0) {
	$position = 0;
	$paging=1;
}	
else
	$position = ($paging -1 ) * $limit;
	
$result = mysql_query("SELECT * FROM image_gallery LIMIT $position, $limit") or die(mysql_error());
$numRows = (mysql_num_rows($result) > $limit)? 20 : mysql_num_rows($result) ;
if ($numRows > 0){
?>
<div align="center">
<div style="width:700px;text-align:left;padding-top:25px;">
	<?php 
		if (isset($confirmation)) {echo $confirmation;}
	?>
	<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
	<script src="js/prototype.js" type="text/javascript"></script>
	<script src="js/scriptaculous.js?load=effects,builder" type="text/javascript"></script>
	<script src="js/lightbox.js" type="text/javascript"></script>
	<script type="text/javascript" src="js/reflection.js"></script>
	<table width="700px" border="0" cellspacing="2" cellpadding="2">
		<?php
		$i = 0;
		//while ($data = mysql_fetch_object($result)){
		for ($rows = 1; $rows<=3; $rows++){
			echo "<tr>";
			for ($cols=1; $cols<=4;$cols++){
				if ($i >= $numRows) break;
				echo '<td style="text-align:center;">';
				$data = mysql_fetch_object($result);
				echo '<div style="width:100px;font-family: verdana; font-size: 11px;">',$data->title;
				echo '<a href="'.$data->path.'" rel="lightbox[roadtrip]">';
				echo '	<span style="border:0px;"><img border="0px" class="reflect" src="'.$data->path.'" width="100" height="100" alt="'.$data->title.'" /></span>';
			echo '</a></div>';						
				echo "</td>";
				$i++;
				}
			echo "</tr>";
			}
		//}
		?>
		<tr>
		<td colspan="4" style="text-align:center;">
			<?php
		if ($totalpaging > 0){
			//Write first and prev navigation
			if ($paging > 1){
				$prevpaging = 0;
				echo '<a style="text-decoration:none;" href="?page=image_gallery&paging=1"><<< First</a> ';
				}else{
				echo "<<< First ";
				}
						
		if ($paging > 1){
			$prevpaging = $paging-1;
			echo '<a style="text-decoration:none;" href="?page=image_gallery&paging='.$prevpaging.'"><< Prev</a> ...';
			}else{
				echo "<< Prev ";
				}

			//write number navigation
			if ($paging > 1){
				$beforepaging = $paging -1 ;
				echo '<a style="text-decoration:none;" href="?page=image_gallery&paging='.$beforepaging.'">'.$beforepaging.'</a> ';
				}
			if ($paging != 0)	echo $paging;
						
			if ($paging < $totalpaging && $paging != 0){
				$nextpaging = $paging + 1 ;
				echo ' <a style="text-decoration:none;" href="?page=image_gallery&paging='.$nextpaging.'">'.$nextpaging.'</a>';
				}
						
			//write next and last navigation
			if ($paging < $totalpaging){
				$nextpaging = $paging + 1;
				echo '...<a style="text-decoration:none;" href="?page=image_gallery&paging='.$nextpaging.'">Next >></a>';
				}else{
				echo " Next >>";
				}
						
				$pagingDiff = $totalpaging - ($paging - 1);				
  			if ($pagingDiff > 1){							echo ' <a style="text-decoration:none;" href="?page=image_gallery&paging='.$totalpaging.'">Last >>></a>';
			}else{
				echo " Last >>>";
				}
			}
			?>
			</td>
		</tr>
		</table>

Next paging does not work! there is no error message it's just there suppose to be too many pictures to fit in a page, I wonder why the next page does not show up, I also unable to click next!

Edited by davy_yg: n/a

0

@davy. Not trying to be funny, but this is the 6th thread you've started in the last 24 hours. Do you need all these threads or are they related in some way? Otherwise, it seems that every time you hit a problem, the first response is to start a thread on DW as opposed to working on it yourself for a while.

0

Sorry, this is my first webpage using full-php. It's all related in someway. I only post problem that I do not know how to fix it.

I do not write the above code. I copy it from tutorial books or CDs. I do not completely understand the code either. So I am trying to understand them and modified the codes to fit my webpage needs.

0

Here's a novel idea - try learning the language before you start running. It will save time in the long run. Posting questions about trivial issues, because you haven't taken the time to teach yourself the basics won't make the greatest use of contributors' time either.

0

I am currently in the middle of taking PHP Basic Course certification. and plan to continue to next level once I finished it.

Well, just need to learn through trial and errors besides the course I guess. I do not copy the whole codes, though, some of them I wrote, such as the website layout, css, others are modified codes.

Edited by davy_yg: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.