Jump to content

to refresh the page on the same page in pagination


upendra470

Recommended Posts

I have been trying to refresh a page by using meta tag but it is targeted to the first page in pagination. I want to refresh to the earlier page and not the first page. Please help me how to do it?

 

<?php
include "connect.php";

if($_SERVER['REQUEST_METHOD']== "POST")
 {
		 $checkbox = $_POST['subcheckbox']; 
	 $countCheck = count($_POST['subcheckbox']);
	 $page = $_GET['page'];

		for($i=0;$i<$countCheck;$i++)
	 {
		 $del_id  = $checkbox[$i];

		 $sql = "DELETE from gallery where `pic_id` = '$del_id'";
		 $result = mysql_query($sql) or die(mysql_error());

	 }
		 if($result)
	 	 {	
		 ?>
             <meta http-equiv='refresh' content='0;URL=gallery.php?page=<?php echo $page; ?>'>

                 <?php
		 }
		 else
		 {
			 echo "Error: ".mysql_error();
		 }
 }
?>

Here in this code i have got the value of page number from another php file but when i used the same variable to refresh using meta tags....than its not working

No, $_GET['page'] isnt define .The script pops up the message.  Here is my entire code

<?php
include("_includes/header.html");
?>

<script type="text/javascript">
document.title="Control Panel for IHROYDC - Gallery";
checked = false;
      function checkedAll () {
        if (checked == false){checked = true}else{checked = false}
for (var i = 0; i < document.getElementById('myform').elements.length; i++) {
  document.getElementById('myform').elements[i].checked = checked;
}
   }
function validation(){
 valid = 0;
 for(var i = 0; i<document.getElementById('myform').elements.length; i++){
	 if(document.getElementById('myform').elements[i].checked == true){
		valid++;					 
	 }	
	 }
	 if(valid == 0){
		 alert('Please choose atleast one image');
		 return false;
	 }
	 else{
		 return true;
	 }
 }

function validate(f)
{
var chkFlg = false;
	for(var i=0; i < f.length; i++) {
		if(f.elements[i].type=="file" && f.elements[i].value != "") {
			chkFlg = true;
		}
	}
	if(!chkFlg) {
		alert('Please browse/choose at least one file');
		return false;
	}
	//f.pgaction.value='upload';
	return true;
}


function _add_more() {

  var txt = "<input type=\"file\" name=\"image_id[]\">";
  document.getElementById("dvFile").innerHTML += txt;

}
function _sub_less(){
var div = document.getElementById('dvFile');
div.removeChild(div.firstChild);

}
</script>

<div id="body">
<div class="content">
<?php
include "session.php";
?> 

  <h1>Add Gallery	 </h1>
      <form name="myform" id="myform" action="deletegallery.php" method="post" onsubmit="return validation()">
      
<table width="1047" class="gridtable">
  <tr>
<th width="57" class="s1"><input name='maincheckbox' id='maincheckbox' type='checkbox' value='' onclick="checkedAll();" /></th><th width="226" class="s1">Category</th>
    <th width="748" class="s2">Picture</th>
</tr>
<?php
/*
	Place code to connect to your DB here.
*/
include "connect.php";	// include your code to connect to DB.

$tbl_name="gallery";		//your table name
// How many adjacent pages should be shown on each side?
$adjacents = 4;

/* 
   First get total number of rows in data table. 
   If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];

/* Setup vars for query. */
$targetpage = "gallery.php"; 	//your file name  (the name of this file)
$limit =5; 
//$page = 0;							//how many items to show per page
//$page = $_GET['page'];
$page = isset($_GET['page']) ? $_GET['page'] : 0;
if($page) 
	$start = ($page - 1) * $limit; 			//first item to display on this page
else
	$start = 0;								//if no page var is given, set start to 0

/* Get data. */
$sql = "SELECT * FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql);

/* Setup page vars for display. */
if ($page == 0) $page = 1;					//if no page var is given, default to 1.
$prev = $page - 1;							//previous page is page - 1
$next = $page + 1;							//next page is page + 1
$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1;						//last page minus 1

/* 
	Now we apply our rules and draw the pagination object. 
	We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{	
	$pagination .= "<div class=\"pagination\">";
	//previous button
	if ($page > 1) 
		$pagination.= "<a href=\"$targetpage?page=$prev\">« previous</a>";
	else
		$pagination.= "<span class=\"disabled\">« previous</span>";	

	//pages	
	if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
	{	
		for ($counter = 1; $counter <= $lastpage; $counter++)
		{
			if ($counter == $page)
				$pagination.= "<span class=\"current\">$counter</span>";
			else
				$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
		}
	}
	elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
	{
		//close to beginning; only hide later pages
		if($page < 1 + ($adjacents * 2))		
		{
			for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
			$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
		}
		//in middle; hide some front and some back
		elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
		{
			$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
			$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
			$pagination.= "...";
			for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
			$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
		}
		//close to end; only hide early pages
		else
		{
			$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
			$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
			$pagination.= "...";
			for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
			}
		}
	}

	//next button
	if ($page < $counter - 1) 
		$pagination.= "<a href=\"$targetpage?page=$next\">next »</a>";
	else
		$pagination.= "<span class=\"disabled\">next »</span>";
	$pagination.= "</div>\n";		
}	
?>
<tr>      
      
<?php


while($data = mysql_fetch_array($result))   {
?> 
  
<td><input name="subcheckbox[]" id="subcheckbox[]" type="checkbox" value ="<?php echo $data['pic_id']; ?>"/></td>
    <td><?php echo $data['category']; ?></td>
    <td><?php 	echo '<img src="upload/gallery/'.$data['pic_name'].'" width="80" height="80" style="margin:0 auto;"/>'; ?></td>
</tr>
<?php } ?>
</table>
<?php echo $pagination; ?>
  <h1> </h1>
     	  <p>Delete marked users : 
    <input type="submit" name="delete" id="delete" value="Delete"  />
        </form>
  </p>
  <p> </p>
      <form name="form1"  id="form1" enctype="multipart/form-data" onsubmit = "return validate(this)" action="addgallery.php" method="post">
  <table width="1045" border="0">
    <tr>
      <td width="304" class="s1">Choose Picture:</td>
      <td width="352" class="s2"><div id="dvFile"><input type="file" name="image_id[]" id="image_id[]" /></div><a href="javascript:_add_more();" title="Add more">
     <img src="img/add2.png" border="0" height="40" width="40"><a href="javascript:_sub_less();" title="Add more">
     <img src="img/minus.png" border="0" height="40" width="60"></td>
        </tr>
    <tr>
      <td class="s1">Category:</td>
      <td class="s2">
        <select name="category" size="1" id="category">
              <option value="Media">Media</option>
          <option value="Activities">Activities</option>
          
          </select></td>
        </tr>
    <tr>
      <td class="s1">Description:</td>
      <td class="s2">
          <textarea name="desc" id="desc" cols="55" rows="5"></textarea></td>
        </tr>
    <tr>
      <td> </td>
      <td class="s2"><input type="submit" name="addimages"  value="Add Image"></td>
        </tr>
      </table>
      </form>
  <p> </p>
<p> </p>
<p> </p>
<p> </p>
  </div>
<div class="footer"></div>
</div>

</div><?php
include("_includes/footer.html");
?>


 

Please help. I am trying to refresh the page to the same page in pagination.

I'll help you fix this, but I won't fix it for you.

 

In the form's action that submits the information sent to your delete page, add ?page=$pagenumbervar

 

so

 

<form method="post" action="delete.php?page=$pagenumbervar">

 

That should do it.

No its not working. It says:

mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Cpanel\gallery.php on line 201

 

and the page does not refresh to the same page. Can you tell me how to send pagenumbervariable to delete.php using form action. I did it like this

 

<form name="myform" id="myform" action="deletegallery.php?page=<?php echo $page;?>" method="post" onsubmit="return validation()">

No, but the entry has been deleted from the database. It is just the warning . Please tell me whether i have send the value of pagenumbervariable correctly or not?? And am I writing the php code inside the meta tag correclty??

 

<meta http-equiv='refresh' content='2;URL=gallery.php?page=<?php echo $page; ?>'>

 

Tell me where I am wrong??

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.