<?php 

//CONNECTION TO DATABASE!

$host="localhost";      // Host name 
$username="root";       // Mysql username 
$password="";           // Mysql password 
$db_name="accounts";    // Database name
$tbl_name="login";      // Table name
$tbl1_name="details";   // Table1 name

$con=mysql_connect("$host","$username","$password");
mysql_select_db("$db_name",$con);

$show_all=$_POST['rg01'];    // Show All
//echo $show_all;

if($show_all!="")
{
$sql="SELECT * FROM $tbl1_name WHERE sex='$show_all'";
$result=mysql_query($sql);	
}
else
{
	echo "SELECT EITHER BRIDE or GROOM";
}

//**EDIT TO YOUR TABLE NAME, ECT. 

$t = mysql_query("SELECT * FROM $tbl1_name WHERE `cat` = '".addslashes($_GET['cat'])."'"); 
  if(!$t) die(mysql_error()); 
    
$a                = mysql_fetch_object($t); 
$total_items      = mysql_num_rows($t); 
$limit            = $_GET['limit']; 
$type             = $_GET['type']; 
$page             = $_GET['page']; 

//set default if: $limit is empty, non numerical, less than 10, greater than 50 
if((!$limit)  || (is_numeric($limit) == false) || ($limit < 10) || ($limit > 50)) { 
     $limit = 5; //default 
} 
//set default if: $page is empty, non numerical, less than zero, greater than total available 
if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) { 
      $page = 1; //default 
} 

//calcuate total pages 
$total_pages     = ceil($total_items / $limit); 
$set_limit       = $page * $limit - ($limit); 

//query: **EDIT TO YOUR TABLE NAME, ECT. 

$q = mysql_query("SELECT * FROM tbl1_name WHERE `cat` = '".addslashes($_GET['cat'])."' LIMIT $set_limit, $limit"); 
  if(!$q) die(mysql_error()); 
     $err = mysql_num_rows($q); 
       if($err == 0) die("No matches met your criteria."); 

//Results per page: **EDIT LINK PATH** 
echo("   
<a href=http://localhost/wamp/www/new.php?cat=$cat&amp;limit=5&amp;page=1>5</a> |"); 

//show data matching query: 
while($code = mysql_fetch_object($q)) { 
     echo("item: ".$code->title."<BR>"); 
} 

$cat = urlencode($cat); //makes browser friendly 

//prev. page: **EDIT LINK PATH** 

$prev_page = $page - 1; 

if($prev_page >= 1) { 
  echo("<b>&lt;&lt;</b> <a href=http://localhost/wamp/www/new.php?cat=$cat&amp;limit=$limit&amp;page=$prev_page><b>Prev.</b></a>"); 
} 

//Display middle pages: **EDIT LINK PATH** 

for($a = 1; $a <= $total_pages; $a++) 
{ 
   if($a == $page) { 
      echo("<b> $a</b> | "); //no link 
     } else { 
  echo("  <a href=http://localhost/wamp/www/new.php?cat=$cat&amp;limit=$limit&amp;page=$a> $a </a> | "); 
     } 
} 

//next page: **EDIT THIS LINK PATH** 

$next_page = $page + 1; 
if($next_page <= $total_pages) { 
   echo("<a href=http://localhost/wamp/www/new.php?cat=$cat&amp;limit=$limit&amp;page=$next_page><b>Next</b></a> &gt; &gt;"); 
} 
?>

i got this code online, when i run it for my page getting Error Notice like this...

Notice: Undefined index: cat in C:\wamp\www\28_09_pm_new\new.php on line 102
Unknown column 'cat' in 'where clause'

this is due to query at line no 30 & 54...

someone help me...
Thankx in Advance...

$t = mysql_query("SELECT * FROM $tbl1_name WHERE `cat` = '".addslashes($_GET['cat'])."'");

and

$q = mysql_query("SELECT * FROM tbl1_name WHERE `cat` = '".addslashes($_GET['cat'])."' LIMIT $set_limit, $limit");

I'm not exactly sure where line 102 would be in this code, since daniweb shows it stopping at line 95, but the error message:
Notice: Undefined index: cat in C:\wamp\www\28_09_pm_new\new.php on line 102
Unknown column 'cat' in 'where clause'

refers to your database. You probably do not have it set up correctly, like however the author of the script had their database set up. This query requires that the table you are addressing (tbl1_name) needs an indexed column named cat. Since this is an indexed column, that means that it also probably appears in another table as well.

You might want to check with the author of that script to make sure that you have your database set up correctly, or restructure the query so that it reflects the column you are trying to address.

One other thing, you might have a cat column in the correct table, but it also may not be indexed. This could also cause a problem - hope that helps

Last error cleared by neccesarry corrections... but now...
it shows 1st page with records, not others.
link to others pages not working (link was there but no page was found)

<?php 
//REMEMBER TO CONNECT TO DATABASE!

$show_all=$_POST['rg01'];    // Show All
//echo $show_all;

$host="localhost";      // Host name 
$username="root";       // Mysql username 
$password="";           // Mysql password 
$db_name="accounts";    // Database name
$tbl_name="login";      // Table name
$tbl1_name="details";   // Table1 name

// Connect to server & select databse.
$con=mysql_connect("$host","$username","$password");
mysql_select_db("$db_name",$con);

if($show_all!="")
{
$sql="SELECT username FROM $tbl1_name WHERE sex='$show_all'";
$result=mysql_query($sql);	
}

else
{
	echo "SELECT EITHER BRIDE or GROOM";
//	header("location:profile search.php");
}

//**EDIT TO YOUR TABLE NAME, ECT. 

$t = mysql_query("SELECT username FROM $tbl1_name WHERE sex = '$show_all'"); 
  if(!$t) die(mysql_error()); 
    
$a                = mysql_fetch_object($t); 
$total_items      = mysql_num_rows($t); 
$limit            = 3; 
//$type             = $_GET['type']; 
$page             = 1; 

//set default if: $limit is empty, non numerical, less than 10, greater than 50 
if((!$limit)  || (is_numeric($limit) == false) || ($limit < 10) || ($limit > 50)) { 
     $limit = 3; //default 
} 
//set default if: $page is empty, non numerical, less than zero, greater than total available 
if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) { 
      $page = 1; //default 
} 

//calcuate total pages 
$total_pages     = ceil($total_items / $limit); 
$set_limit       = $page * $limit - ($limit); 

//query: **EDIT TO YOUR TABLE NAME, ECT. 

$q = mysql_query("SELECT username FROM $tbl1_name WHERE sex = '$show_all' LIMIT $set_limit, $limit"); 
  if(!$q) die(mysql_error()); 
     $err = mysql_num_rows($q); 
       if($err == 0) die("No matches met your criteria."); 
	   

$s_a = urlencode($show_all); //makes browser friendly 

//Results per page: **EDIT LINK PATH** 
//echo("<a href=http://localhost/wamp/www/new.php?sex=$s_a&amp;limit=2&amp;page=1>DART</a> |"); 
echo "<br>";

//show data matching query: 
while($code = mysql_fetch_object($q)) { 
     echo("item: ".$code->username."<BR>"); 
} 

//prev. page: **EDIT LINK PATH** 

$prev_page = $page - 1; 

if($prev_page >= 1) { 
  echo("<b>&lt;&lt;</b> <a href=http://localhost/wamp/www/28_09_pm_new/new.php?sex=$s_a&amp;limit=$limit&amp;page=$prev_page><b>Prev.</b></a>"); 
} 

//Display middle pages: **EDIT LINK PATH** 
for($a = 1; $a <= $total_pages; $a++) 
{ 
   if($a == $page) 
   { 
      echo("<b> $a</b> | "); //no link 
   }
   else 
   { 
    echo("  <a href=http://localhost/wamp/www/28_09_pm_new/new.php?sex=$s_a&amp;limit=$limit&amp;page=$a> $a </a> | "); 
   }
} 

//next page: **EDIT THIS LINK PATH** 
if($page==$total_pages)
{
if($page!=$total_pages)
{
  $next_page = $page + 1; 
  if($next_page <= $total_pages) 
  { 
   echo("<a href=http://localhost/wamp/www/28_09_pm_new/new.php?sex=$s_a&amp;limit=$limit&amp;page=$next_page><b>Next</b></a> &gt; &gt;"); 
  } 
}
}
//all done 
?>

Your links are all pointing to the wrong location and should be something like as follows:

<?php 
//REMEMBER TO CONNECT TO DATABASE!

$show_all=$_POST['rg01'];    // Show All
//echo $show_all;

$host="localhost";      // Host name 
$username="root";       // Mysql username 
$password="";           // Mysql password 
$db_name="accounts";    // Database name
$tbl_name="login";      // Table name
$tbl1_name="details";   // Table1 name

// Connect to server & select databse.
$con=mysql_connect("$host","$username","$password");
mysql_select_db("$db_name",$con);

if($show_all!="")
{
$sql="SELECT username FROM $tbl1_name WHERE sex='$show_all'";
$result=mysql_query($sql);	
}

else
{
	echo "SELECT EITHER BRIDE or GROOM";
//	header("location:profile search.php");
}

//**EDIT TO YOUR TABLE NAME, ECT. 

$t = mysql_query("SELECT username FROM $tbl1_name WHERE sex = '$show_all'"); 
  if(!$t) die(mysql_error()); 
    
$a                = mysql_fetch_object($t); 
$total_items      = mysql_num_rows($t); 
$limit            = 3; 
//$type             = $_GET['type']; 
$page             = 1; 

//set default if: $limit is empty, non numerical, less than 10, greater than 50 
if((!$limit)  || (is_numeric($limit) == false) || ($limit < 10) || ($limit > 50)) { 
     $limit = 3; //default 
} 
//set default if: $page is empty, non numerical, less than zero, greater than total available 
if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) { 
      $page = 1; //default 
} 

//calcuate total pages 
$total_pages     = ceil($total_items / $limit); 
$set_limit       = $page * $limit - ($limit); 

//query: **EDIT TO YOUR TABLE NAME, ECT. 

$q = mysql_query("SELECT username FROM $tbl1_name WHERE sex = '$show_all' LIMIT $set_limit, $limit"); 
  if(!$q) die(mysql_error()); 
     $err = mysql_num_rows($q); 
       if($err == 0) die("No matches met your criteria."); 
	   

$s_a = urlencode($show_all); //makes browser friendly 

//Results per page: **EDIT LINK PATH** 
//echo("<a href=http://localhost/new.php?sex=$s_a&amp;limit=2&amp;page=1>DART</a> |"); 
echo "<br>";

//show data matching query: 
while($code = mysql_fetch_object($q)) { 
     echo("item: ".$code->username."<BR>"); 
} 

//prev. page: **EDIT LINK PATH** 

$prev_page = $page - 1; 

if($prev_page >= 1) { 
  echo("<b>&lt;&lt;</b> <a href=http://localhost/28_09_pm_new/new.php?sex=$s_a&amp;limit=$limit&amp;page=$prev_page><b>Prev.</b></a>"); 
} 

//Display middle pages: **EDIT LINK PATH** 
for($a = 1; $a <= $total_pages; $a++) 
{ 
   if($a == $page) 
   { 
      echo("<b> $a</b> | "); //no link 
   }
   else 
   { 
    echo("  <a href=http://localhost/28_09_pm_new/new.php?sex=$s_a&amp;limit=$limit&amp;page=$a> $a </a> | "); 
   }
} 

//next page: **EDIT THIS LINK PATH** 
if($page==$total_pages)
{
if($page!=$total_pages)
{
  $next_page = $page + 1; 
  if($next_page <= $total_pages) 
  { 
   echo("<a href=http://localhost/28_09_pm_new/new.php?sex=$s_a&amp;limit=$limit&amp;page=$next_page><b>Next</b></a> &gt; &gt;"); 
  } 
}
}
//all done 
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.