PDA

View Full Version : Is it possible to hide rows in a dynamic table?


smitho
04-10-2008, 06:41 AM
I have a dynamic table and as it builds the users flags/tick what they have done with each row of data. In one of the columns I have completed as the status. Once the user has ticked completed the information does not need to be shown in the table only the ones that are not complete. Is there a way to hide the data from the table?

I currently have :

<tr if ($rowlist['complete']=='Y') {echo "calss=\"green\"";}>

which will change the row color to green.

<tr if ($rowlist['complete']=='Y') {echo "style=\"visibility:hidden\"";}>

"visibility:hidden" will hide the data but the row is still there. Need to hide the row.

smitho
04-10-2008, 07:44 AM
Worked out:

{echo "style=\"display:none\"";}will do the trick just need to work out how to turn it off and on.

Might try and check box or button but need it to stay set so if you refresh the page it does not turn off.

student101
04-11-2008, 07:38 AM
You should add that or this in the CSS


.posthide {
display:none
}
.postshow {
display:inline
}

<tr if ($rowlist['complete']=='Y') class="posthide">

Cheers

smitho
04-13-2008, 02:28 PM
Got this working with a button but I found a little problem. I'm using pages to navigate through the table as it gets bigger and bigger. What I found was that when the display:none is active all that happened is the row disappears but the table length stays the same.

A quick test I did with 8 entries in the database I set 2 to be completed. I set the max row display for each page to 6 so this meant I had 6 on my first page and 2 on the second. When I hit the button to hide the 2 complete rows I still have 2 pages. 5 on the first page and 1 on the second.

Could this because of the way I created the paging? Should display:none take it out of the list and only so me one page?

student101
04-13-2008, 05:23 PM
Post your code.

smitho
04-14-2008, 12:21 AM
Here's the code I've adapted to davidj's examples that way anyone who has gone through his tuts can use this code as well.

The only thing you'll need to do is add another field to the users table called showhide and set it to a varchar (4).

Rather than use completed as my flag in database table1 field2 has a number of values set to 0. The show/hide button will flag them as green when show is active and then hide then when you click hide.


<?php
require_once("Connections/dwc.php"); // database connection
///////////////////////////////////////////
@$data2 = $_POST['data2'];
@$data3 = $_POST['data3'];
@$data4 = $_POST['data4'];
@$submit = $_POST['submit'];
@$update_id = $_POST['update_id'];
@$del = $_GET['del'];
@$upd = $_GET['upd'];
///////////////////////////////////////////

$currentPage = $_SERVER["PHP_SELF"];

$maxRows = 5;
$noRows = 0;
if (isset($_GET['noRows'])) {
$noRows = $_GET['noRows'];
}
$startRow = $noRows * $maxRows;

///////////////////////////////////////////
$query = sprintf("SELECT * FROM table1 where field1_id='$upd'");
$result = @mysql_query($query);
$rowUpdate = @mysql_fetch_array($result);
///////////////////////////////////////////
if ($submit && $data2 && $data3 && $data4 && ! $update_id){
///////////////////////////////////////////
$query = sprintf("INSERT into table1 (field2, field3, field4) values ('$data2', '$data3', '$data4')");
mysql_query($query)or die(mysql_error());
///////////////////////////////////////////
}elseif($submit && $update_id){
///////////////////////////////////////////
$query = sprintf("UPDATE table1 set field2='$data2', field3='$data3', field4='$data4' where field1_id = '$update_id'");
$result = @mysql_query($query);
///////////////////////////////////////////
}
///////////////////////////////////////////
$query = sprintf("SELECT * FROM table1 where field1_id='$upd'");
$result = @mysql_query($query);
$rowUpdate = @mysql_fetch_array($result);
///////////////////////////////////////////
//delete record
if ($del){
///////////////////////////////////////////
$query = sprintf("DELETE FROM table1 where field1_id='$del'");
mysql_query($query)or die(mysql_error());
///////////////////////////////////////////
}
///////////////////////////////////////////
if(!isset($_POST['data2filter'])||!isset($_POST['data3filter'])){
$query = sprintf("SELECT * FROM table1");
}else{
$data2filter=$_POST['data2filter'];
if(!$data2filter){
$data2filter = "%";
}
$data3filter=$_POST['data3filter'];
if(!$data3filter){
$data3filter = "%";
}
$query = "SELECT * FROM table1 WHERE field2 LIKE '%$data2filter%' AND field3 LIKE '%$data3filter%'";
}
$query_limit = sprintf("%s LIMIT %d, %d", $query, $startRow, $maxRows);
$result = @mysql_query($query_limit);
$row = mysql_fetch_array($result);
///////////////////////////////////////////
if (isset($_GET['totalRows'])) {
$totalRows = $_GET['totalRows'];
} else {
$all = mysql_query($query);
$totalRows = mysql_num_rows($all);
}
$totalPages = ceil($totalRows/$maxRows)-1;

$queryString = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "noRows") == false &&
stristr($param, "totalRows") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString = sprintf("&totalRows=%d%s", $totalRows, $queryString);

//do {
//echo $row['field3']."<br>";
//}while ($row = mysql_fetch_array($result))
@$filterdata2=$_POST['data2filter'];
@$filterdata3=$_POST['data3filter'];

//echo $totalRows;

/////////////////////////////////////
$disquery = sprintf("SELECT * FROM users WHERE user_id='1'");
$disresult = @mysql_query($disquery);
$disrow = mysql_fetch_array($disresult);
/////////////////////////////////////

//$dis=$disrow['showhide'];


if($disrow['showhide']=='Show'){
$dis='Hide';
$color="class='green'";
}else{
$dis='Show';
$color="style='display:none'";
}
@$display=$_POST['ShowHide'];

if(isset($_POST['ShowHide'])){
/////////////////////////////////////
$query = sprintf("UPDATE users SET showhide='$display' WHERE user_id='1'");
mysql_query($query)or die(mysql_error);
header("Location: $_SERVER[PHP_SELF]");
/////////////////////////////////////
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.green {
background-color: #00FF00;
}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<table width="1" border="1">
<tr>
<td>data2</td>
<td>data3</td>
<td>data4</td>
</tr>
<tr>
<td><input type="text" name="data2" id="data2" value="<?php echo $rowUpdate['field2'];?>"/></td>
<td><input type="text" name="data3" id="data3" value="<?php echo $rowUpdate['field3'];?>"/></td>
<td><input type="text" name="data4" id="data4" value="<?php echo $rowUpdate['field4'];?>"/></td>
</tr>
<tr>
<td colspan="3"><div align="center">
<input type="button" name="submit3" value="Clear" onclick="document.location.href='dwc3.php'"/>
<input type="reset" name="submit2" value="Reset" />
<input type="submit" name="Submit" value="Submit" />
<input name="submit" type="hidden" id="submit" value="1" />
<input name="update_id" type="hidden" id="update_id" value="<?php echo $rowUpdate['field1_id'];?>" />
</div></td>
</tr>
</table>
<p>&nbsp;</p>
</form>
<p>&nbsp;</p>
<form id="filter" name="filter" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<table width="50%" border="1" cellpadding="2" cellspacing="2">
<tr>
<td><input type="submit" name="button2" id="button2" value="Filter" /></td>
<td>&nbsp;</td>
<td><input type="text" name="data2filter" id="data2filter" value="<?php echo $filterdata2;?>"/></td>
<td><input type="text" name="data3filter" id="data3filter" value="<?php echo $filterdata3;?>"/></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>ID1</td>
<td>data2</td>
<td>data3</td>
<td>data4</td>
<td>&nbsp;</td>
</tr>
<?php do { ?>
<tr <?php if ($row['field2']=='0') {echo "$color";}?>>
<td><input type="button" name="button" id="button" value="Update" onclick="document.location.href='dwc3.php?upd=<?php echo $row['field1_id'];?>'" /></td>
<td><?php echo $row['field1_id'];?></td>
<td><?php echo $row['field2'];?></td>
<td><?php echo $row['field3'];?></td>
<td><?php echo $row['field4'];?></td>
<td><input type="button" name="button" id="button" value="Delete" onclick="document.location.href='dwc3.php?del=<?php echo $row['field1_id'];?>'" /></td>
</tr>
<?php }while ($row = mysql_fetch_array($result)); ?>
</table>
</form>
<span class="style9">Records <?php echo ($noRows + 1) ?> to <?php echo min($noRows + $maxRows, $totalRows) ?> of <?php echo $totalRows ?></span>
<table border="0">
<tr>
<td><?php if ($noRows > 0) { // Show if not first page ?>
<a href="<?php printf("%s?noRows=%d%s", $currentPage, 0, $queryString); ?>">First</a>
<?php } // Show if not first page ?> </td>
<td><?php if ($noRows > 0) { // Show if not first page ?>
<a href="<?php printf("%s?noRows=%d%s", $currentPage, max(0, $noRows - 1), $queryString); ?>">Previous</a>
<?php } // Show if not first page ?> </td>
<td><?php if ($noRows < $totalPages) { // Show if not last page ?>
<a href="<?php printf("%s?noRows=%d%s", $currentPage, min($totalPages, $noRows + 1), $queryString); ?>">Next</a>
<?php } // Show if not last page ?> </td>
<td><?php if ($noRows < $totalPages) { // Show if not last page ?>
<a href="<?php printf("%s?noRows=%d%s", $currentPage, $totalPages, $queryString); ?>">Last</a>
<?php } // Show if not last page ?> </td>
</tr>
</table>
<form id="form2" name="form2" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<label>
<input type="submit" name="ShowHide" id="ShowHide" value="<?php echo $dis; ?>" />
</label>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>

smitho
04-14-2008, 05:55 AM
Just realized the example I posted was one after using dreamweavers auto paging. This one has been cut down. I've added the show/hide button. After seeing the link to the paging tut I'm wondering if I would be able to tie in the filter with the paging. Currently if you apply a filter the table it will work but as soon as you fit the next page link the filter is lost.


<?php
require_once("Connections/dwc.php"); // database connection
///////////////////////////////////////////

@$data2 = $_POST['data2'];
@$data3 = $_POST['data3'];
@$data4 = $_POST['data4'];
@$submit = $_POST['submit'];
@$update_id = $_POST['update_id'];
@$del = $_GET['del'];
@$upd = $_GET['upd'];
///////////////////////////////////////////

$currentPage=$_SERVER['PHP_SELF']; //set the current Page this way so that you can use this with any page

$maxRows = 5; //to change the number of rows displayed set 5 to any number you wish
$noRows = 0; //this is our starting row number
if (isset($_GET['noRows'])) { //if if a page link is hit get increase the $noRow by either + or - $maxRows
$noRows = $_GET['noRows'];
}

$firstPage = 0; //first page will always be 0
$nextPage = $noRows + $maxRows; //next page will be + $maxRows
$prevPage = $noRows - $maxRows; //previous page will always be - $maxRows



///////////////////////////////////////////
$query = sprintf("SELECT * FROM table1 where field1_id='$upd'");
$result = @mysql_query($query);
$rowUpdate = @mysql_fetch_array($result);
///////////////////////////////////////////
if ($submit && ! $update_id){
///////////////////////////////////////////
$query = sprintf("INSERT into table1 (field2, field3, field4) values ('$data2', '$data3', '$data4')");
mysql_query($query)or die(mysql_error());
///////////////////////////////////////////
}elseif($submit && $update_id){
///////////////////////////////////////////
$query = sprintf("UPDATE table1 set field2='$data2', field3='$data3', field4='$data4' where field1_id = '$update_id'");
$result = @mysql_query($query);
///////////////////////////////////////////
}
///////////////////////////////////////////
$query = sprintf("SELECT * FROM table1 where field1_id='$upd'");
$result = @mysql_query($query);
$rowUpdate = @mysql_fetch_array($result);
///////////////////////////////////////////
//delete record
if ($del){
///////////////////////////////////////////
$query = sprintf("DELETE FROM table1 where field1_id='$del'");
mysql_query($query)or die(mysql_error());
///////////////////////////////////////////
}
///////////////////////////////////////////
if(!isset($_POST['data2filter'])||!isset($_POST['data3filter'])){
$query = sprintf("SELECT * FROM table1 LIMIT $noRows, $maxRows"); //set the query to display the LIMIT we set.
}else{
$data2filter=$_POST['data2filter'];
if(!$data2filter){
$data2filter = "%";
}
$data3filter=$_POST['data3filter'];
if(!$data3filter){
$data3filter = "%";
}
$query = "SELECT * FROM table1 WHERE field2 LIKE '%$data2filter%' AND field3 LIKE '%$data3filter%'"; //we can also limit the filter list by the LIMIT we set.
}
$allrows = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
///////////////////////////////////////////

$all = mysql_query($allrows); //because we have a limit set the query we need to set another query to determine the number of rows in our database.
$totalRows = mysql_num_rows($all);
$totalPages = ceil($totalRows/$maxRows)-1; //now that me now the number we can determine the number of pages -1 to get the last page.
$lastPage = $totalPages * $maxRows; //to get the last page as a row figure we multiple totalpages by the maxrows.


@$filterdata2=$_POST['data2filter'];
@$filterdata3=$_POST['data3filter'];

/////////////////////////////////////
$disquery = sprintf("SELECT * FROM users WHERE user_id='1'");
$disresult = @mysql_query($disquery);
$disrow = mysql_fetch_array($disresult);
/////////////////////////////////////

//$dis=$disrow['showhide'];


if($disrow['showhide']=='Show'){
$dis='Hide';
$color="class='green'";
}else{
$dis='Show';
$color="style='display:none'";
}
@$display=$_POST['ShowHide'];

if(isset($_POST['ShowHide'])){
/////////////////////////////////////
$query = sprintf("UPDATE users SET showhide='$display' WHERE user_id='1'");
mysql_query($query)or die(mysql_error);
header("Location: $_SERVER[PHP_SELF]");
/////////////////////////////////////
}

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.green {
background-color: #33FF66;
}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<table width="1" border="1">
<tr>
<td>data2</td>
<td>data3</td>
<td>data4</td>
</tr>
<tr>
<td><input type="text" name="data2" id="data2" value="<?php echo $rowUpdate['field2'];?>"/></td>
<td><input type="text" name="data3" id="data3" value="<?php echo $rowUpdate['field3'];?>"/></td>
<td><input type="text" name="data4" id="data4" value="<?php echo $rowUpdate['field4'];?>"/></td>
</tr>
<tr>
<td colspan="3"><div align="center">
<input type="button" name="submit3" value="Clear" onclick="document.location.href='dwc2.php'"/>
<input type="reset" name="submit2" value="Reset" />
<input type="submit" name="Submit" value="Submit" />
<input name="submit" type="hidden" id="submit" value="1" />
<input name="update_id" type="hidden" id="update_id" value="<?php echo $rowUpdate['field1_id'];?>" />
</div></td>
</tr>
</table>
<p>&nbsp;</p>
</form>
<p>&nbsp;</p>
<form id="filter" name="filter" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<table width="50%" border="1" cellpadding="2" cellspacing="2">
<tr>
<td><input type="submit" name="button2" id="button2" value="Filter" /></td>
<td>&nbsp;</td>
<td><input type="text" name="data2filter" id="data2filter" value="<?php echo $filterdata2;?>"/></td>
<td><input type="text" name="data3filter" id="data3filter" value="<?php echo $filterdata3;?>"/></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>ID1</td>
<td>data2</td>
<td>data3</td>
<td>data4</td>
<td>&nbsp;</td>
</tr>
<?php do { ?>
<tr <?php if ($row['field2']=='0') {echo "$color";}?>>
<td><input type="button" name="button" id="button" value="Update" onclick="document.location.href='dwc2.php?upd=<?php echo $row['field1_id'];?>'" /></td>
<td><?php echo $row['field1_id'];?></td>
<td><?php echo $row['field2'];?></td>
<td><?php echo $row['field3'];?></td>
<td><?php echo $row['field4'];?></td>
<td><input type="button" name="button" id="button" value="Delete" onclick="document.location.href='dwc2.php?del=<?php echo $row['field1_id'];?>'" /></td>
</tr>
<?php }while ($row = mysql_fetch_array($result)); ?>
</table>
</form>
<p>
<?php
//here we create the links to the pages and use the row counts to display the pages.
if ($noRows > 0) { // Show if not first page ?>
<a href="<?php echo sprintf("%s?noRows=%s", $currentPage, $firstPage);?>">First</a>
<?php } // Show if not first page ?>

<?php if ($noRows > 0) { // Show if not first page ?>
<a href="<?php echo sprintf("%s?noRows=%s", $currentPage, $prevPage);?>">Previous</a>
<?php } // Show if not first page ?>

<?php if ($nextPage < $totalRows) { // Show if not last page ?>
<a href="<?php echo sprintf("%s?noRows=%s", $currentPage, $nextPage);?>">Next</a>
<?php } // Show if not last page ?>

<?php if ($nextPage < $totalRows) { // Show if not last page ?>
<a href="<?php echo sprintf("%s?noRows=%s", $currentPage, $lastPage);?>">Last</a>
<?php } // Show if not last page ?>
</p>
<form id="form2" name="form2" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<label>
<input type="submit" name="ShowHide" id="ShowHide" value="<?php echo $dis; ?>" />
</label>
</form>
<p>&nbsp;</p>
</body>
</html>

student101
04-14-2008, 06:33 AM
Which tutorial is this?
I only now found the arrays tutorial and Davidj never mentioned it once.

Cheers

smitho
04-14-2008, 11:47 AM
If you go to :

http://www.dreamweaverclub.com/vtm/php-mysql-apache.php


and watch "PHP, A Beginners Guide"

Part9 , 10 and 11.

you'll get the base for what I've put here. I like using this as an example to build on and test.

Cheers.

student101
04-14-2008, 12:00 PM
Cool, thanks.

I'll check it out to understand what you need better.

Cheers

smitho
04-15-2008, 03:27 AM
Although the show/hide button looks nice I don't thinks it's going to work. What I'm after is a filter effect that stays set even when you refresh the page, go to the next page or even go to another page and back.

So I'm think what I might try and do is capture the filter text output and store them in an array. Make a new column under the users table called filter and insert the filter options there. That way when the user comes back and if they have filtered the list a certain way it will apply it according to their options.

I've created the filter column in the users table.

Using this code I capture way is in the filter fields and update the database:


$option=array("data2"=>@$_POST['data2filter'], "data3"=>@$_POST['data3filter']);
$options =serialize('$option');
$optquery = sprintf("UPDATE users SET filter='$options' WHERE user_id='1'");
mysql_query($query)or die(mysql_error);

Now I've used serialise() and I'll explain later. This above code adds Array to the filter column.

Now here is my problem I'm trying to get the array details out of the database.


/////////////////////////////////////
$disquery = sprintf("SELECT * FROM users WHERE user_id='1'");
$disresult = @mysql_query($disquery);
$disrow = mysql_fetch_array($disresult);
/////////////////////////////////////

$dboptions= unserialize($disrow['filter']);
To test the results I'm using:


<p><?php print"<pre>"; print_r($option); print"</pre>";?></p>

This returns:
Array
(
[data2] => 234
[data3] =>
)
<p><?php print"<pre>"; print_r($dboptions); print"</pre>";?></p>

This returns:
Notice: unserialize() [function.unserialize]: Error at offset 0 of 5 bytes in...


Now I've used serialize because if I don't I get Array as the return for $disrow['filter']. Unserializing it does not seem to work. What I'm expecting is a result like to print_r($options);

Any suggestions?

smitho
04-15-2008, 06:12 AM
Ok this is almost complete. If someone could help me with combining the paging an filter that would be great.

Just to make it clear the way I got the filter to work was to capture what the user types in the filter field and then update the users database 'filter' column with their entry. This means the list will stick with their filter until they click the clear button which will remove the data from the 'filter' column.

I was trying to find a way to add the filter request that the user typed in to a session or cookie etc but every time the page was reset the filter was lost. If anyone can tell me if this is possible that would be great. This was the only way I could get it to work. I also left the show/hide button in if anyone was interested.

Here's the code:


<?php
require_once("Connections/dwc.php"); // database connection
///////////////////////////////////////////

@$data2 = $_POST['data2'];
@$data3 = $_POST['data3'];
@$data4 = $_POST['data4'];
@$submit = $_POST['submit'];
@$update_id = $_POST['update_id'];
@$del = $_GET['del'];
@$upd = $_GET['upd'];
@$filter = $_POST['Filter'];
@$clear = $_POST['Clear'];
///////////////////////////////////////////

$currentPage=$_SERVER['PHP_SELF']; //set the current Page this way so that you can use this with any page

$maxRows = 5; //to change the number of rows displayed set 5 to any number you wish
$noRows = 0; //this is our starting row number
if (isset($_GET['noRows'])) { //if if a page link is hit get increase the $noRow by either + or - $maxRows
$noRows = $_GET['noRows'];
}

$firstPage = 0; //first page will always be 0
$nextPage = $noRows + $maxRows; //next page will be + $maxRows
$prevPage = $noRows - $maxRows; //previous page will always be - $maxRows



///////////////////////////////////////////
$query = sprintf("SELECT * FROM table1 where field1_id='$upd'");
$result = @mysql_query($query);
$rowUpdate = @mysql_fetch_array($result);
///////////////////////////////////////////
if ($submit && ! $update_id){
///////////////////////////////////////////
$query = sprintf("INSERT into table1 (field2, field3, field4) values ('$data2', '$data3', '$data4')");
mysql_query($query)or die(mysql_error());
///////////////////////////////////////////
}elseif($submit && $update_id){
///////////////////////////////////////////
$query = sprintf("UPDATE table1 set field2='$data2', field3='$data3', field4='$data4' where field1_id = '$update_id'");
$result = @mysql_query($query);
///////////////////////////////////////////
}
///////////////////////////////////////////
$query = sprintf("SELECT * FROM table1 where field1_id='$upd'");
$result = @mysql_query($query);
$rowUpdate = @mysql_fetch_array($result);
///////////////////////////////////////////
//delete record
if ($del){
///////////////////////////////////////////
$query = sprintf("DELETE FROM table1 where field1_id='$del'");
mysql_query($query)or die(mysql_error());
///////////////////////////////////////////
}


$option =array("data2"=>@$_POST['data2filter'], "data3"=>@$_POST['data3filter']);
$options=serialize($option);

if(isset($filter)){
$optquery = sprintf("UPDATE users SET filter='$options' WHERE user_id='1'");
$optresult = @mysql_query($optquery);
}

if(isset($clear)){
$optquery = sprintf("UPDATE users SET filter='' WHERE user_id='1'");
$optresult = @mysql_query($optquery);
header("Location: $_SERVER[PHP_SELF]");
}

/////////////////////////////////////
$disquery = sprintf("SELECT * FROM users WHERE user_id='1'");
$disresult = @mysql_query($disquery);
$disrow = mysql_fetch_array($disresult);
/////////////////////////////////////

$dboptions= unserialize($disrow['filter']);


///////////////////////////////////////////

$data2filter=$dboptions['data2'];
$data3filter=$dboptions['data3'];

$query = "SELECT * FROM table1 WHERE field2 LIKE '%$data2filter%' AND field3 LIKE '%$data3filter%' LIMIT $noRows, $maxRows"; //we can also limit the filter list by the LIMIT we set.

$allrows = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
///////////////////////////////////////////

$all = mysql_query($allrows); //because we have a limit set the query we need to set another query to determine the number of rows in our database.
$totalRows = mysql_num_rows($all);
$totalPages = ceil($totalRows/$maxRows)-1; //now that me now the number we can determine the number of pages -1 to get the last page.
$lastPage = $totalPages * $maxRows; //to get the last page as a row figure we multiple totalpages by the maxrows.


if($disrow['showhide']=='Show'){
$dis='Hide';
$color="class='green'";
}else{
$dis='Show';
$color="style='display:none'";
}
@$display=$_POST['ShowHide'];

if(isset($_POST['ShowHide'])){
/////////////////////////////////////
$query = sprintf("UPDATE users SET showhide='$display' WHERE user_id='1'");
mysql_query($query)or die(mysql_error);
header("Location: $_SERVER[PHP_SELF]");
/////////////////////////////////////
}

@$filterdata2=$dboptions['data2'];
@$filterdata3=$dboptions['data3'];


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.green {
background-color: #33FF66;
}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<table width="1" border="1">
<tr>
<td>data2</td>
<td>data3</td>
<td>data4</td>
</tr>
<tr>
<td><input type="text" name="data2" id="data2" value="<?php echo $rowUpdate['field2'];?>"/></td>
<td><input type="text" name="data3" id="data3" value="<?php echo $rowUpdate['field3'];?>"/></td>
<td><input type="text" name="data4" id="data4" value="<?php echo $rowUpdate['field4'];?>"/></td>
</tr>
<tr>
<td colspan="3"><div align="center">
<input type="button" name="submit3" value="Clear" onclick="document.location.href='dwc2.php'"/>
<input type="reset" name="submit2" value="Reset" />
<input type="submit" name="Submit" value="Submit" />
<input name="submit" type="hidden" id="submit" value="1" />
<input name="update_id" type="hidden" id="update_id" value="<?php echo $rowUpdate['field1_id'];?>" />
</div></td>
</tr>
</table>
<p>&nbsp;</p>
</form>
<p><?php print"<pre>"; print_r($dboptions); print"</pre>";?></p>
<form id="filter" name="filter" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<table width="50%" border="1" cellpadding="2" cellspacing="2">
<tr>
<td><input type="submit" name="Filter" id="Filter" value="Filter" />
<input type="submit" name="Clear" id="Clear" value="Clear" /></td>
<td>&nbsp;</td>
<td><input type="text" name="data2filter" id="data2filter" value="<?php echo $dboptions['data2'];?>"/></td>
<td><input type="text" name="data3filter" id="data3filter" value="<?php echo $filterdata3;?>"/></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>ID1</td>
<td>data2</td>
<td>data3</td>
<td>data4</td>
<td>&nbsp;</td>
</tr>
<?php do { ?>
<tr <?php if ($row['field2']=='0') {echo "$color";}?>>
<td><input type="button" name="button" id="button" value="Update" onclick="document.location.href='dwc2.php?upd=<?php echo $row['field1_id'];?>'" /></td>
<td><?php echo $row['field1_id'];?></td>
<td><?php echo $row['field2'];?></td>
<td><?php echo $row['field3'];?></td>
<td><?php echo $row['field4'];?></td>
<td><input type="button" name="button" id="button" value="Delete" onclick="document.location.href='dwc2.php?del=<?php echo $row['field1_id'];?>'" /></td>
</tr>
<?php }while ($row = mysql_fetch_array($result)); ?>
</table>
</form>
<p><span class="style9">Records <?php echo ($noRows + 1) ?> to <?php echo min($noRows + $maxRows, $totalRows) ?> of <?php echo $totalRows ?></span></p>
<p>
<?php
//here we create the links to the pages and use the row counts to display the pages.
if ($noRows > 0) { // Show if not first page ?>
<a href="<?php echo sprintf("%s?noRows=%s", $currentPage, $firstPage);?>">First</a>
<?php } // Show if not first page ?>

<?php if ($noRows > 0) { // Show if not first page ?>
<a href="<?php echo sprintf("%s?noRows=%s", $currentPage, $prevPage);?>">Previous</a>
<?php } // Show if not first page ?>

<?php if ($nextPage < $totalRows) { // Show if not last page ?>
<a href="<?php echo sprintf("%s?noRows=%s", $currentPage, $nextPage);?>">Next</a>
<?php } // Show if not last page ?>

<?php if ($nextPage < $totalRows) { // Show if not last page ?>
<a href="<?php echo sprintf("%s?noRows=%s", $currentPage, $lastPage);?>">Last</a>
<?php } // Show if not last page ?>
</p>
<form id="form2" name="form2" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<label>
<input type="submit" name="ShowHide" id="ShowHide" value="<?php echo $dis; ?>" />
</label>
</form>
<p>&nbsp;</p>
</body>
</html>
My problem with paging is here:

$data2filter=$dboptions['data2'];
$data3filter=$dboptions['data3'];

$query = "SELECT * FROM table1 WHERE field2 LIKE '%$data2filter%' AND field3 LIKE '%$data3filter%' LIMIT $noRows, $maxRows"; //we can also limit the filter list by the LIMIT we set.

$allrows = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
///////////////////////////////////////////

$all = mysql_query($allrows); //because we have a limit set the query we need to set another query to determine the number of rows in our database.
$totalRows = mysql_num_rows($all);
$totalPages = ceil($totalRows/$maxRows)-1; //now that me now the number we can determine the number of pages -1 to get the last page.
$lastPage = $totalPages * $maxRows; //to get the last page as a row figure we multiple totalpages by the maxrows.


Due to the LIMIT $noRows, $maxRows (to set the table rows 5 deep) what happens is the paging counts all the rows, so if the filter finds 8 entries but the database has 18 entries all up the paging works to the 18 not the 8. Should be able to nut it out but is any can point it out faster that would be great.