472,368 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,368 software developers and data experts.

Problem on paging

chelvan
90
Hi Forums
When i doing following code, it do the query & show the result contain pages. but when i move to the next page that displays the error message.

the error message is :

Notice: Undefined index: h1 in C:\AppServ\www\facebook\findpepoles.php on line 65 (marked as ------error #1)

Notice: Undefined index: txtser in C:\AppServ\www\facebook\findpepoles.php on line 66 (marked as ------error #2)


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con=mysql_connect("localhost","root","iceberg");
  3. if(!$con){
  4.     die('could not connect:'.mysql_error());
  5.     }
  6. mysql_select_db("mydata",$con);
  7. $recordsPerPage = 6; 
  8. $pageNum = 1;
  9. if(isset($_GET['p'])) {
  10.   $pageNum = $_GET['p'];
  11.   settype($pageNum, 'integer');
  12. }
  13. $offset = ($pageNum - 1) * $recordsPerPage;
  14.  
  15. $db_c=0;
  16. $pr_c=0;
  17.  
  18. $username=$_POST['h1']; //-------------------error #1
  19. $servalue=$_POST['txtser'];//-------------------error 2
  20.  
  21. $myref=$refno;
  22.  
  23. if($servalue=='')
  24. {
  25. echo " ";
  26. echo "Enter Your Friend Name,City or Country To Find Your Match";
  27. }
  28. else
  29. {
  30. $sql_sel=mysql_query("SELECT * FROM user WHERE fullname='$servalue' or city='$servalue' or country='$servalue' LIMIT $offset, $recordsPerPage");
  31. $sql_sel1=mysql_query("SELECT * FROM user WHERE fullname='$servalue' or city='$servalue' or country='$servalue' ");
  32.  
  33.  
  34.  
  35. while($row=mysql_fetch_array($sql_sel)){
  36.     $frienduse[$db_c]=$row['username'];
  37.     $friendref[$db_c]=$row['refno'];
  38.     $fullname[$db_c]=$row['fullname'];
  39.     $country[$db_c]=$row['country'];
  40.     $lookingfor[$db_c]=$row['lookingFor'];
  41.     $religious[$db_c]=$row['religious'];
  42.     $friendimg[$db_c]=$row['prophoto'];
  43.  
  44.     $db_c=$db_c+1;
  45. }
  46. }
  47. /*if($db_c==0){
  48.     $db_c==1;
  49. }*/
  50.  
  51.  
  52.  
  53. echo "<p align='right'><a href='home.php'>Home</a></p>";
  54. echo "<table align='center'>";
  55. while($pr_c<$db_c){
  56. echo"<tr><td rowspan='5' valign='middle'>";
  57. echo "<a href='serView.php'><img src='img/".$friendimg[$pr_c]."' width='115' heught='120'></a>";echo "&nbsp;</td></tr>";
  58. //echo"<tr><td>";
  59. //echo $friendref[$pr_c]; echo "&nbsp;</td></tr>";
  60. echo"<tr><td>";
  61. echo $fullname[$pr_c];echo "&nbsp;</td><td colspan='50'>&nbsp;</td><td><a href='serView.php?$friendref[$pr_c]'>View Profile</a></td></tr>";
  62. echo"<tr><td>";
  63. echo $country[$pr_c];echo "&nbsp;</td><td colspan='50'>&nbsp;</td><td>Send Message</td></tr>";
  64. echo"<tr><td>";
  65. echo $lookingfor[$pr_c];echo "&nbsp;</td><td colspan='50'>&nbsp;</td><td><a href='addmyFriends.php?$friendref[$pr_c]'>Friendship</a></td></tr>";
  66. echo"<tr><td>";
  67. echo $religious[$pr_c];echo "&nbsp;<br><br></td></tr>";
  68.  
  69. //echo "<br><br>";
  70. $pr_c=$pr_c+1;
  71. }
  72. echo"</table>";
  73.  
  74.  $query   = "SELECT COUNT(refno) AS dt FROM user WHERE fullname='$servalue' or city='$servalue' or country='$servalue';";
  75.  
  76.   $result  = mysql_query($query) or die('Mysql Err. 2');
  77.   $row     = mysql_fetch_assoc($result);
  78.   $numrows = $row['dt'];
  79.  
  80.   $maxPage = ceil($numrows/$recordsPerPage);
  81.  
  82.   $nav = '';
  83.   for($page = 1; $page <= $maxPage; $page++)
  84.   {
  85.        if ($page == $pageNum)
  86.        {
  87.             $nav .= "<div class=\"pNo\">$page</div>";
  88.        }
  89.       else
  90.        {
  91.             $nav .= "<div class=\"pNo\"><a href=\"?p=$page\">$page</a></div>";
  92.        }
  93.   }
  94.  
  95.   if ($pageNum > 1)  {
  96.  
  97.        $page = $pageNum - 1;
  98.        $prev = "<a href=\"?p=$page\"><strong><</strong></a>";
  99.  
  100.        $first = "<a href=\"?p=1\"><strong><<</strong></a>";
  101.   }
  102.   else {
  103.        $prev  = '<strong>  </strong>';
  104.        $first = '<strong>   </strong>';
  105.   }
  106.  
  107.   if ($pageNum < $maxPage) {
  108.        $page = $pageNum + 1;
  109.        $next = "<a href=\"?p=$page\"><strong>></strong></a>";
  110.  
  111.        $last = "<a href=\"?p=$maxPage\"><strong>>></strong></a>";
  112.   }
  113.   else {
  114.        $next = '<strong>  </strong>';
  115.        $last = '<strong>   </strong>';
  116.   }
  117.    echo '<br />'; 
  118.   echo '<br />';
  119.  
  120.   echo "<div class=\"pagingDiv\">
  121.       <div class=\"pNo\">$first</div>
  122.       <div class=\"pNo\">$prev</div>
  123.       $nav
  124.       <div class=\"pNo\">$next</div>
  125.       <div class=\"pNo\">$last</div></div>";
  126. ?>
  127.  
i couldn't understand that? can any one explain that?


thanks
chel-1
Sep 25 '08 #1
5 1521
Atli
5,058 Expert 4TB
Hi.

And undefined index warning means that you are trying to use an array element that doesn't exist.

You need to find where that is happening and make sure the element does exist before you try to use it.

The isset function can help with that.
Sep 25 '08 #2
chelvan
90
Hi.

And undefined index warning means that you are trying to use an array element that doesn't exist.

You need to find where that is happening and make sure the element does exist before you try to use it.

The isset function can help with that.
thanks atli.
i try to find that.

chel-1
Sep 26 '08 #3
chelvan
90
hi
now my question is....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con=mysql_connect("localhost","root","iceberg");
  3.  
  4. if(!$con){
  5. die('could not connect:'.mysql_error());
  6. }
  7. mysql_select_db("mydata",$con);
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. // how many rows to show per page
  15. $rowsPerPage = 2;
  16.  
  17. // by default we show first page
  18. $pageNum = 1;
  19.  
  20. // if $_GET['page'] defined, use it as page number
  21. if(isset($_GET['page']))
  22. {
  23.     $pageNum = $_GET['page'];
  24. }
  25.  
  26. // counting the offset
  27. $offset = ($pageNum - 1) * $rowsPerPage;
  28.  
  29. echo "<table align='center' border='0'>";
  30.  
  31. $sql_fr=mysql_query("SELECT*FROM myfriends WHERE refno='$refno'");
  32. while($row=mysql_fetch_array($sql_fr)){
  33.     $fref[$my]= $row['myfriend'];
  34.  
  35.     $query = " SELECT * FROM user WHERE refno='$fref[$my]'" .
  36.          " LIMIT $offset, $rowsPerPage";
  37. $result = mysql_query($query) or die('Error, query failed');
  38.  
  39. // print 
  40. while($row = mysql_fetch_array($result)){
  41.       $fname[$my]=$row['fullname'];
  42.     $photo[$my]=$row['prophoto'];
  43.     $em[$my]=$row['email'];
  44.     $bd[$my]=$row['birthdate'];
  45.  
  46.     $em[$my]=substr($em[$my],0,strpos($em[$my],"/"));
  47.     $pos[$my]=strpos($fname[$my],' ');
  48.      $fname[$my]=substr($fname[$my],0,$pos[$my]);
  49.  
  50.     $my+=1;
  51.     }
  52. }
  53.  
  54.  
  55. echo "<table align='center' border='0'>";
  56. while($fr_c<$my){
  57.     echo"<tr><td rowspan='5' aligh='middle'><img src='img/".$photo[$fr_c]."' width='115' height='120'></td></tr>";
  58.     echo "<tr><td>".$fname[$fr_c]."</td><td width='200'></td><td><a href='viewgrps.php?$fref[$fr_c]'>View Groups</a></td></tr>";
  59.     echo "<tr><td>".$em[$fr_c]."</td><td width='200'></td><td><a href='fralbpage.php?$fref[$fr_c]'>View Albums</a></td></tr>";
  60.     echo "<tr><td>".$bd[$fr_c]."</td><td width='200'></td><td><a href='events.php'>View Events</a></td></tr>";
  61.     echo "<tr><td>Send Message</td></tr>";
  62.     echo"<tr><td>&nbsp;</td></tr>";
  63.     $fr_c+=1;
  64.     }
  65. echo "</table>";
  66.  
  67. // how many rows we have in database
  68. $query   = "SELECT COUNT(refno) AS numrows FROM myfriends WHERE refno='$refno'";
  69. $result  = mysql_query($query) or die('Error, query failed');
  70. $row     = mysql_fetch_array($result, MYSQL_ASSOC);
  71. $numrows = $row['numrows'];
  72.  
  73. // how many pages we have when using paging?
  74. $maxPage = ceil($numrows/$rowsPerPage);
  75.  
  76. // print the link to access each page
  77. $self = $_SERVER['PHP_SELF'];
  78. $nav  = '';
  79.  
  80. for($page = 1; $page <= $maxPage; $page++)
  81. {
  82.    if ($page == $pageNum)
  83.    {
  84.       $nav .= " $page "; // no need to create a link to current page
  85.    }
  86.    else
  87.    {
  88.       $nav .= " <a href=\"$self?page=$page\">$page</a> ";
  89.    } 
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. // creating previous and next link
  100. // plus the link to go straight to
  101. // the first and last page
  102.  
  103. if ($pageNum > 1)
  104. {
  105.    $page  = $pageNum - 1;
  106.    $prev  = " <a href=\"$self?page=$page\">[Prev]</a> ";
  107.  
  108.    $first = " <a href=\"$self?page=1\">[First Page]</a> ";
  109. else
  110. {
  111.    $prev  = '&nbsp;'; // we're on page one, don't print previous link
  112.    $first = '&nbsp;'; // nor the first page link
  113. }
  114.  
  115. if ($pageNum < $maxPage)
  116. {
  117.    $page = $pageNum + 1;
  118.    $next = " <a href=\"$self?page=$page\">[Next]</a> ";
  119.  
  120.    $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
  121. else
  122. {
  123.    $next = '&nbsp;'; // we're on the last page, don't print next link
  124.    $last = '&nbsp;'; // nor the last page link
  125. }
  126.  
  127. // print the navigation link
  128. echo "<br><br>";
  129. echo $first . $prev . $nav . $next . $last;
  130.  
  131. // and close the database connection
  132.  
  133.  
  134.  
  135.  
  136. mysql_close();
  137.  
  138. ?>
  139.  
  140.  

the above paging code find the num of rows on database & it define the upcoming pages. but my problem is on the next page doesn't have any data.
why?

thanks
chel-1
Sep 26 '08 #4
what comes to my mind is that you're trying to do a query while looping in the results of another query in this part. I'm not really sure if you could do that. I would recommend to first finish working with all the results from one query, store the info you need in an array and then work on the second query with that array OR create two links to the DB and then one query use it with one link and the other with the second link.

Cheers,

Gabo

Expand|Select|Wrap|Line Numbers
  1. while($row=mysql_fetch_array($sql_fr)){
  2.     $fref[$my]= $row['myfriend'];
  3.  
  4.     $query = " SELECT * FROM user WHERE refno='$fref[$my]'" .
  5.          " LIMIT $offset, $rowsPerPage";
  6. $result = mysql_query($query) or die('Error, query failed');
  7.  
  8. // print 
  9. while($row = mysql_fetch_array($result)){
  10.       $fname[$my]=$row['fullname'];
  11.     $photo[$my]=$row['prophoto'];
  12.     $em[$my]=$row['email'];
  13.     $bd[$my]=$row['birthdate'];
  14.  
  15.     $em[$my]=substr($em[$my],0,strpos($em[$my],"/"));
  16.     $pos[$my]=strpos($fname[$my],' ');
  17.      $fname[$my]=substr($fname[$my],0,$pos[$my]);
  18.  
  19.     $my+=1;
  20.     }
  21. }
  22.  
Sep 29 '08 #5
chelvan
90
what comes to my mind is that you're trying to do a query while looping in the results of another query in this part. I'm not really sure if you could do that. I would recommend to first finish working with all the results from one query, store the info you need in an array and then work on the second query with that array OR create two links to the DB and then one query use it with one link and the other with the second link.

Cheers,

Gabo

Expand|Select|Wrap|Line Numbers
  1. while($row=mysql_fetch_array($sql_fr)){
  2.     $fref[$my]= $row['myfriend'];
  3.  
  4.     $query = " SELECT * FROM user WHERE refno='$fref[$my]'" .
  5.          " LIMIT $offset, $rowsPerPage";
  6. $result = mysql_query($query) or die('Error, query failed');
  7.  
  8. // print 
  9. while($row = mysql_fetch_array($result)){
  10.       $fname[$my]=$row['fullname'];
  11.     $photo[$my]=$row['prophoto'];
  12.     $em[$my]=$row['email'];
  13.     $bd[$my]=$row['birthdate'];
  14.  
  15.     $em[$my]=substr($em[$my],0,strpos($em[$my],"/"));
  16.     $pos[$my]=strpos($fname[$my],' ');
  17.      $fname[$my]=substr($fname[$my],0,$pos[$my]);
  18.  
  19.     $my+=1;
  20.     }
  21. }
  22.  

thanks Gabo!
now its working.

chel-1
Sep 30 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Li | last post by:
Hi, guys, I got a problem when trying to paging the recordset. the problem is even I set the pagesize but the first page will always show all the records and the number of records that shown on...
0
by: Paul Perot | last post by:
Hi All: I am populating a Data Table with File/Folder information from my drive... I am then binding this data table to a DataGrid. Due to the size of the DataGrid data, I use the built in...
2
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
6
by: hlubocky | last post by:
I thought I had a good grasp of the problem related to dynamically creating controls, but it appears that as my application grew in complexity, the problem has resurfaced. As I understand it, in...
5
by: LRK | last post by:
Earlier this week we set up a second application pool to be able to implement trusted connections between ASP.NET apps and a SQL Server database on a different server. The trusted connection is...
0
by: anonieko | last post by:
This approach I found very efficient and FAST when compared to the rowcount, or Subquery Approaches. This is before the advent of a ranking function from DB such as ROW_NUMBER() in SQL Server...
4
by: Chuck | last post by:
I'm setting the column with for a gridview (25+- columns) and have paging turned on. When the gridview is first displayed, the column widths are all set to the default. But after paging to...
5
by: Donald Adams | last post by:
Hi, I will have both web and win clients and would like to page my data. I could not find out how the datagrid control does it's paging though I did find some sample code that says they do it...
7
by: m.gelosa | last post by:
Dear all, I got a problem on db2 for aix running a high workload messaging system with more than 5,000,000 of deliveries per day. During high peak hours it happens frequently that the...
0
by: webaccess | last post by:
Hi Friends ..!! I want to use datagrid/dataview control to data in tablular format,also I want to add paging and format the data of table column. Problem is data is coming from API Dom in as...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.