Jump to content

Recommended Posts

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");
?>

Link to comment
https://forums.phpfreaks.com/topic/85122-pegination-help/
Share on other sites

 

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.

Link to comment
https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434232
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434298
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/85122-pegination-help/#findComment-434361
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.