Pradeep_Chinna Posted October 2, 2013 Share Posted October 2, 2013 This is the code what tried. Data is divided and displayd no.of pages too... But, when i click 2link/page, its showng sorry no data found. Help me... <?php $name = $_POST['name']; $category = $_POST['category']; $con = mysql_connect("localhost","zxzx","xzxz") or die("Unable to connect"); $db = mysql_select_db("test",$con) or die("Unable to select DB"); if(isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } $sf = ($page-1) * 16; $sql = " SELECT * FROM budget where NAME=\"$name\" LIMIT ".$sf.",16 "; $rs = mysql_query($sql,$con); if(mysql_num_rows($rs) == 0) { echo("<p class=\"no\">Sorry, NO Records Found..!</p> <p class=\"no\">Please try with another Name.</p> "); } else { echo "<table id='main-table' cellspacing='0' cellpadding='0' class=\"table1\"> <tr class=\"rowh\"> <td>Date</td> <td>Name</td> <td colspan=\"2\"> ACTIONS </td> </tr>"; while ($row=mysql_fetch_array($rs)) { echo ("<tr><td class=\"rowr\">$row[DATE]</td>"); echo ("<td class=\"rowr\">$row[NAME]</td>"); echo ("<td ><a class=\"rowrl\" href=\"edit_form.php?number=$row[iD]\"> Edit </a></td>"); echo ("<td ><a class=\"rowrl\" href=\"delete.php?number=$row[iD]\" onclick=\"return confirm(' Do you really want to DELETE ?');\"> Delete </a></td></tr>"); } } </table> </td> </tr> </table> <?php $sql1 = "SELECT COUNT(NAME) FROM BUDGET where NAME=\"$name\" "; $rs1 = mysql_query($sql1,$con); $row1 = mysql_fetch_row($rs1); $total = $row1[0]; $tp = ceil($total/16); for($i = 1; $i <= $tp; $i++) { echo "<a href='edit.php?page=".$i."'>".$i."</a> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/282631-how-to-get-data-from-db-page-by-page/ Share on other sites More sharing options...
Ch0cu3r Posted October 2, 2013 Share Posted October 2, 2013 (edited) Your code relies on the $_POST['name'] value, this is coming from the form you submitted to edit.php. Now it will work fine on the first page as this value is present. But it is not when you click on any of the page links as this value is not being carried over. If you don't pass it back to edit.php $name will be empty and your sql query $sql = " SELECT * FROM budget where NAME=\"$name\" LIMIT ".$sf.",16 ";wont return any data and thus you get the sorry no data found message To preserve the value you'll need to pass the name within your page links to edit.php echo "<a href='edit.php?name=".$name."&page=".$i."'>".$i."</a> "; Now change $name = $_POST['name']; to $name = isset($_POST['name']) ? $_POST['name'] : isset($_GET['name']) ? $_GET['name'] : ''; if(empty(trim($name))) echo 'Name required'; The above code will first check to see if the name has been submitted by _POST (from your form). If it is it'll set $name to that value. If _POST['name'] doesn't exits it'll see if it is in the url (values passed in the url is retrieved using _GET). If that value is found it'll set $name to $_GET['name']. Otherwise it'll set $name to emtpy. The if statement checks to make sure $name is not empty and if it is displays a message saying name required. Edited October 2, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282631-how-to-get-data-from-db-page-by-page/#findComment-1452156 Share on other sites More sharing options...
Pradeep_Chinna Posted October 3, 2013 Author Share Posted October 3, 2013 Getting fatal error bro...! Error: cant use function return value in write context in at if(empty(trim($name))). I've tried with is_resource and empty($name) too.... Not displayng my data...! Quote Link to comment https://forums.phpfreaks.com/topic/282631-how-to-get-data-from-db-page-by-page/#findComment-1452392 Share on other sites More sharing options...
Solution Ch0cu3r Posted October 3, 2013 Solution Share Posted October 3, 2013 (edited) Sorry Change $name = isset($_POST['name']) ? $_POST['name'] : isset($_GET['name']) ? $_GET['name'] : ''; if(empty(trim($name))) echo 'Name required';to $name = (isset($_POST['name']) ? $_POST['name'] : (isset($_GET['name']) ? $_GET['name'] : '')); if(empty($name)) echo 'Name required';Should work ok now? Edited October 3, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282631-how-to-get-data-from-db-page-by-page/#findComment-1452400 Share on other sites More sharing options...
Pradeep_Chinna Posted October 3, 2013 Author Share Posted October 3, 2013 (edited) Succccceeeesssss......:-O:-O:-O thanks alot my dear...:-) Edited October 3, 2013 by Pradeep_Chinna Quote Link to comment https://forums.phpfreaks.com/topic/282631-how-to-get-data-from-db-page-by-page/#findComment-1452409 Share on other sites More sharing options...
cyberRobot Posted October 3, 2013 Share Posted October 3, 2013 I have marked the topic as solved. If you need anything else, please mark it as unsolved...or start a new topic. Quote Link to comment https://forums.phpfreaks.com/topic/282631-how-to-get-data-from-db-page-by-page/#findComment-1452418 Share on other sites More sharing options...
Pradeep_Chinna Posted October 3, 2013 Author Share Posted October 3, 2013 Thank u:-) Solved 100%...:-) Quote Link to comment https://forums.phpfreaks.com/topic/282631-how-to-get-data-from-db-page-by-page/#findComment-1452419 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.