risi Posted January 9, 2008 Share Posted January 9, 2008 Hi all, I am using script that is really cool right now! but I have some problems including pagination to it. Could someone help me with it? Here is code. Well I tried many ways to include it but still have no solution to it. The script is very Hard coded. I guess so. Thank you anyway. and best regards. <? function main() { include "../includes/conn.php"; include "../includes/function.php"; if($_REQUEST['act']=="del") { $ch_id=$_REQUEST['ch_id']; mysql_query("delete from channel where ch_id=$ch_id"); print '<script language="javascript">window.location="manage_channel.php";</script>'; } if($_REQUEST['act']=="top") { $ch_id=$_REQUEST['ch_id']; mysql_query("update channel set top_flag=1 where ch_id=$ch_id"); print '<script language="javascript">window.location="manage_channel.php";</script>'; } else if($_REQUEST['act']=="nottop") { $ch_id=$_REQUEST['ch_id']; mysql_query("update channel set top_flag=0 where ch_id=$ch_id"); print '<script language="javascript">window.location="manage_channel.php";</script>'; } include "../includes/config.php"; include "../lang/$langfile/global.php"; ?> <script language="javascript"> function chkavial() { <? $chk=mysql_query("select * from channel where top_flag=1"); $num=mysql_num_rows($chk); if($num>5) { ?> alert('Please You can make 5 top channel only'); return false; <? } ?> } </script> <form action="" method="post" name="frm"> <table align="center" class="maintable-channels" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="pagetitle" colspan="5"><?= $lang_channelmanager ?></td> <tr> <td class="cellheader"><?= $lang_numid ?></td> <td class="cellheader"><?= $lang_channelname ?></td> <td class="cellheader"><?= $lang_chandescription ?></td> <td class="cellheader"><?= $lang_catname ?></td> <td class="cellheader"><?= $lang_action ?></td> </tr> <? $ch_res=mysql_query("select * from channel order by channel_name ASC"); if(mysql_num_rows($ch_res)>0) { $i=1; while($ch_row=mysql_fetch_array($ch_res)) { $cat_name=getname($ch_row[cat_id],'cat_id','category','cat_name'); //geting stone name $flg=$ch_row[top_flag]; ?> <tr> <td class="tablecells1"><?=$i?></td> <td class="tablecells"> <?=stripslashes($ch_row[channel_name])?></td> <td class="tablecells2"> <?=stripslashes($ch_row[channel_description])?></td> <td class="tablecells"><?=$cat_name?> </td> <td class="tablecells4"><a href="addchannel.php?act=edit&ch_id=<?=$ch_row[ch_id]?>" class="footer"><?= $lang_edit ?></a> | <a href="manage_channel.php?act=del&ch_id=<?=$ch_row[ch_id]?>" class="footer" onClick="return confirm('<?=$lang_question?>');"><?= $lang_delete ?></a></td> </tr> <? $i++; } } else { ?> <tr> <td colspan="5" align="center"><font color="#FF0000" size="+1"><?= $lang_recnotfound ?></font></td> </tr> <? } ?> <tr> <td></td> <td></td> <td></td> <td></td> <td id="addnewbutton"><a href="addchannel.php" ><?= $lang_addnemcat ?></a></td> </tr> </table> </form> <? } include("style/template.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/85122-pegination-help/ Share on other sites More sharing options...
corillo181 Posted January 9, 2008 Share Posted January 9, 2008 if you read this tutorial http://www.phpfreaks.com/tutorials/43/0.php you will have a better idea of how to include a pagination. Quote Link to comment https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434223 Share on other sites More sharing options...
risi Posted January 9, 2008 Author Share Posted January 9, 2008 Hi! Thanks for your answer but I am reading it already all day long. it is already 04:30 here and I am still sitting on my sofa trying to get the answer to it. thanks again and best regards. Quote Link to comment https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434225 Share on other sites More sharing options...
Ken2k7 Posted January 9, 2008 Share Posted January 9, 2008 What is with all the REQUEST and redirection? Why would you mysql_query something (that may be false), then not use it and just redirect the user? And they all redirect to the same place. Quote Link to comment https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434229 Share on other sites More sharing options...
risi Posted January 9, 2008 Author Share Posted January 9, 2008 Did you mean about this code? $ch_id=$_REQUEST['ch_id']; mysql_query("delete from channel where ch_id=$ch_id"); print '<script language="javascript">window.location="manage_channel.php";</script>'; } if($_REQUEST['act']=="top") { $ch_id=$_REQUEST['ch_id']; mysql_query("update channel set top_flag=1 where ch_id=$ch_id"); print '<script language="javascript">window.location="manage_channel.php";</script>'; } else if($_REQUEST['act']=="nottop") { $ch_id=$_REQUEST['ch_id']; mysql_query("update channel set top_flag=0 where ch_id=$ch_id"); print '<script language="javascript">window.location="manage_channel.php";</script>'; } This is Administration area. it is redirecting to modify, delete or add new item. Quote Link to comment https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434232 Share on other sites More sharing options...
Ken2k7 Posted January 9, 2008 Share Posted January 9, 2008 Okay, first tell us what you're trying to do and why it's not working. Second, explain to me why you use mysql_query() before you redirect the user. BTW, you could've used the header() function in PHP to redirect the user rather than using JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434247 Share on other sites More sharing options...
risi Posted January 9, 2008 Author Share Posted January 9, 2008 OK... The problem is simple. I am able to sort 3 items per page but I can't get to next or previous pages pages. <? function main() { include "../includes/conn.php"; include "../includes/function.php"; if($_REQUEST['act']=="del") { $ch_id=$_REQUEST['ch_id']; mysql_query("delete from channel where ch_id=$ch_id"); print '<script language="javascript">window.location="manage_channel.php";</script>'; } if($_REQUEST['act']=="top") { $ch_id=$_REQUEST['ch_id']; mysql_query("update channel set top_flag=1 where ch_id=$ch_id"); print '<script language="javascript">window.location="manage_channel.php";</script>'; } else if($_REQUEST['act']=="nottop") { $ch_id=$_REQUEST['ch_id']; mysql_query("update channel set top_flag=0 where ch_id=$ch_id"); print '<script language="javascript">window.location="manage_channel.php";</script>'; } include "../includes/config.php"; include "../lang/$langfile/global.php"; ?> <script language="javascript"> function chkavial() { <? $chk=mysql_query("select * from channel where top_flag=1"); $num=mysql_num_rows($chk); if($num>5) { ?> alert('Please You can make 5 top channel only'); return false; <? } ?> } </script> <? $limit = 3; $query_count = "SELECT count(*) FROM channel"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); $query = "SELECT * FROM channel LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } ?> <form action="" method="post" name="frm"> <table align="center" class="maintable-channels" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="pagetitle" colspan="5"><?= $lang_channelmanager ?></td> <tr> <td class="cellheader"><?= $lang_numid ?></td> <td class="cellheader"><?= $lang_channelname ?></td> <td class="cellheader"><?= $lang_chandescription ?></td> <td class="cellheader"><?= $lang_catname ?></td> <td class="cellheader"><?= $lang_action ?></td> </tr> <? $query=mysql_query("select * from channel order by channel_name ASC LIMIT $limitvalue, $limit"); if(mysql_num_rows($query)>0) { $i=1; while($ch_row = mysql_fetch_array($query)){ { $cat_name=getname($ch_row[cat_id],'cat_id','category','cat_name'); //geting stone name $flg=$ch_row[top_flag]; ?> <tr> <td class="tablecells1"><?=$i?></td> <td class="tablecells"> <?=stripslashes($ch_row[channel_name])?></td> <td class="tablecells2"> <?=stripslashes($ch_row[channel_description])?></td> <td class="tablecells"><?=$cat_name?> </td> <td class="tablecells4"><a href="addchannel.php?act=edit&ch_id=<?=$ch_row[ch_id]?>" class="footer"><?= $lang_edit ?></a> | <a href="manage_channel.php?act=del&ch_id=<?=$ch_row[ch_id]?>" class="footer" onClick="return confirm('<?=$lang_question?>');"><?= $lang_delete ?></a></td> </tr> <? $i++; } } } else { ?> <tr> <td colspan="5" align="center"><font color="#FF0000" size="+1"><?= $lang_recnotfound ?></font></td> </tr> <? } ?> <tr> <td></td> <td></td> <td></td> <td></td> <td id="addnewbutton"><a href="addchannel.php" ><?= $lang_addnemcat ?></a></td> </tr> </table> <? if($page != 1){ $pageprev = $page--; echo("<a href=\"&page=$pageprev\">PREV</a> "); }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"?page=$pagenext\">NEXT</a>"); }else{ echo("NEXT".$limit); } mysql_free_result($result); ?> </form> <? } include("style/template.php"); ?> so here Links are not clickable just the Prev, 1, and Next is displayed. when I try to submit address on my own to ?page=2 and so on it still gets the same page with same items inside. This is where I'm stuck! <? if($page != 1){ $pageprev = $page--; echo("<a href=\"&page=$pageprev\">PREV</a> "); }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"?page=$pagenext\">NEXT</a>"); }else{ echo("NEXT".$limit); } mysql_free_result($result); ?> Just I am trying to figure out how to change this issue. About JavaScript: I use javascript it is true and sad. I will change it to $PHP_SELF but first I need to finish this one. Quote Link to comment https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434298 Share on other sites More sharing options...
Ken2k7 Posted January 9, 2008 Share Posted January 9, 2008 Okay, now I don't wish to change what you're thinking of and make you start over, but I posted this template for someone else and I think you'll find it helpful. Maybe this will give you an idea on what you can do: <?php // database connection stuff // // this will get the page number from the URL // $page_number = $_GET['page']; // now you want to find out how many results you // want to display per page. // You may want to use mysql_num_rows and then // divide by $number_of_pages to get $results_per_page // if you're going to do that, take the ceil of $number_of_pages $number_of_pages = 20; $results_per_page = 10; // find the starting result of the page // if each page has $results_per_page results, it's easy to // find the starting point given $page_number $starting_point = ($page_number - 1) * $result_per_page + 1; // find ending result $ending_point = $page_number * $result_per_page // here is what your query should look like $query = "SELECT * FROM table_name LIMIT $starting_point, $ending_point"; // rest up to you, this is just to start you off in the right direction of thinking // when setting up the links to pages, make sure you put something like page= // so $_GET['page'] can get the current page number ?> Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434361 Share on other sites More sharing options...
rameshfaj Posted January 9, 2008 Share Posted January 9, 2008 You can find lots of pagination stuffs in this site itself, I have also tried some of them, they worked well, u can also try them! Quote Link to comment https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434441 Share on other sites More sharing options...
risi Posted January 9, 2008 Author Share Posted January 9, 2008 there is a problem in this code! http://www.phpfreaks.com/tutorials/43/5.php it doesn't work fine. I will try to make my own and then I will show you my results. Quote Link to comment https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434536 Share on other sites More sharing options...
Ken2k7 Posted January 9, 2008 Share Posted January 9, 2008 there is a problem in this code! http://www.phpfreaks.com/tutorials/43/5.php it doesn't work fine. I will try to make my own and then I will show you my results. Yeah, it's out-dated. If you follow my template, it should work fine. Quote Link to comment https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434672 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.