IreneLing Posted October 12, 2011 Share Posted October 12, 2011 Hi all . I have a script , which will display the records from sql . If user wish to view more details of the record , they can click view . echo "<td>$objResult[Message] </td>"; echo "<td>$objResult[mylocaltime] </td>"; echo '<td><a href="historydetails.php?id=' . $objResult[Groupnumber] . '">View</a></td>'; Then it will link to a page which will display more details according to the Groupnumber . Which will display 2 records per page . <? $groupnumber = $_GET['id']; $strSQL = "SELECT * FROM esp WHERE Groupnumber='$groupnumber'"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); $Num_Rows = mysql_num_rows($objQuery); $Per_Page = 2; // Per Page $Page = $_GET["Page"]; if(!$_GET["Page"]) { $Page=1; } $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) { $Num_Pages =1; } else if(($Num_Rows % $Per_Page)==0) { $Num_Pages =($Num_Rows/$Per_Page) ; } else { $Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages; } $strSQL .=" order by id DESC LIMIT $Page_Start , $Per_Page"; $objQuery = mysql_query($strSQL); ?> But when I click next to view the third record , then the table will become blank . Is it because when I click to next page , the $groupnumber is no longer getting the data from $_GET['id'] ? Or is there any other problem? Thanks for every reply . Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 12, 2011 Share Posted October 12, 2011 Is it because when I click to next page , the $groupnumber is no longer getting the data from $_GET['id'] ? Or is there any other problem? If you are not passing $groupnumber the the secondary pagination script on the next page loads,then yes, that is the problem. The easiest solutin would be to probably add the groupnumber to the pagination links on the secondary page. Quote Link to comment Share on other sites More sharing options...
IreneLing Posted October 12, 2011 Author Share Posted October 12, 2011 If you are not passing $groupnumber the the secondary pagination script on the next page loads,then yes, that is the problem. The easiest solutin would be to probably add the groupnumber to the pagination links on the secondary page. Thanks for your reply . I tried to look at my scripts again and again , but I have really no idea how to pass the groupnumber to next page load...? Here is my code (not yet complete) <? $groupnumber = $_GET['id']; $strSQL = "SELECT * FROM esp WHERE Groupnumber='$groupnumber'"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); $Num_Rows = mysql_num_rows($objQuery); $Per_Page = 2; // Per Page $Page = $_GET["Page"]; if(!$_GET["Page"]) { $Page=1; } $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) { $Num_Pages =1; } else if(($Num_Rows % $Per_Page)==0) { $Num_Pages =($Num_Rows/$Per_Page) ; } else { $Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages; } $strSQL .=" order by id DESC LIMIT $Page_Start , $Per_Page"; $objQuery = mysql_query($strSQL); ?> <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">ID </div></th> <th width="91"> <div align="center">Groupnumber </div></th> <th width="198"> <div align="center">Message </div></th> <th width="198"> <div align="center">Create on </div></th> </tr> <? echo "<form name='form1' method='post' action=''>"; while($objResult = mysql_fetch_array($objQuery)) { echo "<tr>"; echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[id]\"></td>"; echo "<td>$objResult[id] </td>"; echo "<td>$objResult[Groupnumber]</td>"; echo "<td>$objResult[Message] </td>"; echo "<td>$objResult[mylocaltime] </td>"; echo "</tr>"; } echo "</form>"; ?> </table> <br> Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page : <? if($Prev_Page) { if($_GET["txtFirstName"] == "") { echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> "; } else { echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> "; } } for($i=1; $i<=$Num_Pages; $i++){ if($i != $Page) { echo "[ <a href='$_SERVER[sCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]"; } else { echo "<b> $i </b>"; } } if($Page!=$Num_Pages) { if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "") { echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> "; } else if($_GET["txtFirstName"] == "" ) { echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> "; } else { echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> "; } } mysql_close($objConnect); ?> So...should I add it somewhere....here?? if($Page!=$Num_Pages) { if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "") { echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> "; } else if($_GET["txtFirstName"] == "" ) { echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> "; } else { echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> "; } } Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 12, 2011 Share Posted October 12, 2011 You are getting the $_GET['id']; from the originating page. So, you *should* just need to add that parameter to the links that you create if($Page!=$Num_Pages) { if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "") { echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]&id=$groupnumber'>Next>></a> "; } else if($_GET["txtFirstName"] == "" ) { echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]&id=$groupnumber'>Next>></a> "; } else { echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]&id=$groupnumber'>Next>></a> "; } } Quote Link to comment Share on other sites More sharing options...
IreneLing Posted October 12, 2011 Author Share Posted October 12, 2011 Thank you so much mjdamato , once again you solved my problem...and I learned something new again (to me). Thanks again and wish you have a nice day . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.