0

Hello My Problem May Be Very Easy Or Very Hard

Iam Still Noob In Php

I Developed This Site

http://www.e-alriyadh.com/

The Pagination Works Fine In The Index Page

Like This

http://www.e-alriyadh.com/index.php?p=2

Now There's A Problem In The Category Section Pagination

This Is A Section

http://www.e-alriyadh.com/cat.php?id=22

When I Try To Go To Page 2

It Must Be Like This

http://www.e-alriyadh.com/cat.php?id=22&p=2

Instead Of This

http://www.e-alriyadh.com/cat.php?p=2

I Found In My Pagination Class File This ( Variable ) var $querystring = ''; // example id=1&e=2&r=5 // When I Make It Like This var $querystring = 'id=?????'; // example id=1&e=2&r=5 // Now My Problem How Can I Make The Class Get The ID

I Attached The

Index.php
cat.php
split.php (( Pagination Class ))

I Know I have Many Problems In My Develope Coz Iam Not Expert

But I Wish To Solve This Problem

Attachments
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl" lang="ar">

<head>
<title>::  ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<link rel="stylesheet" type="text/css" href="Style.Css" />

</head>

<body>

<div id="Aziz">

<div id="wrap">
<div id="header">

<a class="zerothedefender" href="advs.php"><img class="zbanner1" src="Zimg/Ad1.Gif" alt="Banner 1" /></a> <img class="zlogo" src="Zimg/Logo.Png" alt="Logo" /> <a class="zerothedefender" href="cell.php"><img class="zbanner2" src="Zimg/Ad2.Gif" alt="Banner 2" /></a>

</div>

<?php

include('func.php');

$id = intval($_GET["id"]);

$headers = headers("tabs.html");
$headers = str_replace("{menu}",menu(),$headers);

echo $headers;

?>

<div class="content"> 
<br/>
<?php

include 'split.php';

$split = new page_spilt("SELECT `id`,`title`,`full` FROM `ads` where cat='$id' AND active='0' ORDER BY `id` DESC", $_GET["Page"]);
$rs = $split->get_results();
if (is_array($rs)) {
    foreach ($rs as $key => $value) {
echo "<div style='width: 186px; height: 174px; float:right; background: transparent url(Zimg/Box.A.Png) no-repeat; padding: 0 4.5px 10px 0px'>"; 
echo "<table width='98%' border='0'>";
echo "<tr>";
echo "<td class='x1'>" . $rs[$key][1] . "</td>";
echo "</tr>";
echo  "<tr>";
echo "<td class='x2'>" . $rs[$key][2] . "</td>";
echo "</tr>";
echo "<tr>
<td><a class='x3' target='_blank' href='details.php?id=". $rs[$key][0]."'></a>
</td>
</tr>";
echo "</table>";
echo "</div>";
    }

?>

</div>

<div class="numbers">
<?php
       $rs = $split->get_numbers();  
    foreach ($rs as $key => $value) {
        if (empty($value))
            echo $key . "&nbsp;&nbsp;";
        else
            echo "<a href=\"$value\">$key</a>&nbsp;&nbsp;";
    }
} else {
    echo "  ";
} 

?>

</div>

<div class="linksfooter">
<?php include "links.html"; ?>
</div>

<div id="footer"> 
<?php include "tags.html" ?>
</div>

</div>
</div>

 <p align="center">
    <a target="_blank" href="http://validator.w3.org/check?uri=referer"><img
        src="http://www.w3.org/Icons/valid-xhtml10"
        alt="Valid XHTML 1.0 Transitional" height="31" width="88" border="0" /></a>
  </p> 

</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl" lang="ar">

<head>
<title>::    ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta name="keywords" content="   :   ,  ,     ,  ,   ,   ,  ,  ,   ,   ,   ,   ,    ,    ,   ,   ,   ,   ,   ,   ,  ,  ,    , ,   ,   ,   ,   ,    ,   ,  ,   ,  ,  ,    ,   ,  , ,   ,  ,  ,   ,  ,   ,  ,   ,  ,   " />
<meta name="description" content="   :   ,  ,     ,  ,   ,   ,  ,  ,   ,   ,   ,   ,    ,    ,   ,   ,   ,   ,   ,   ,  ,  ,    , ,   ,   ,   ,   ,    ,   ,  ,   ,  ,  ,    ,   ,  , ,   ,  ,  ,   ,  ,   ,  ,   ,  ,   " />


<link rel="stylesheet" type="text/css" href="Style.Css" />

</head>

<body>

<div id="Aziz">

<div id="wrap">
<div id="header">

<a class="zerothedefender" href="advs.php"><img class="zbanner1" src="Zimg/Ad1.Gif" alt="Banner 1" /></a> <img class="zlogo" src="Zimg/Logo.Png" alt="Logo" /> <a class="zerothedefender" href="cell.php"><img class="zbanner2" src="Zimg/Ad2.Gif" alt="Banner 2" /></a>

</div>

<?php

include('func.php');

$headers = headers("tabs.html");
$headers = str_replace("{menu}",menu(),$headers);

echo $headers;

?>

<div class="content"> 
<br/>

<?php

require_once 'split.php';

$split = new page_spilt("SELECT `id`,`title`,`full` FROM `ads` where active='0' ORDER BY `id` DESC", $_GET["Page"]);
$rs = $split->get_results();
if (is_array($rs)) {
    foreach ($rs as $key => $value) {
echo "<div style='width: 186px; height: 174px; float:right; background: transparent url(Zimg/Box.A.Png) no-repeat; padding: 0 4.5px 10px 0px'>"; 
echo "<table width='98%' border='0'>";
echo "<tr>";
echo "<td class='x1'>" . $rs[$key][1] . "</td>";
echo "</tr>";
echo  "<tr>";
echo "<td class='x2'>" . $rs[$key][2] . "</td>";
echo "</tr>";
echo "<tr>
<td><a class='x3' target='_blank' href='details.php?id=". $rs[$key][0]."'></a>
</td>
</tr>";
echo "</table>";
echo "</div>";
    }

?>

</div>

<div class="numbers">
<?php
       $rs = $split->get_numbers();  
    foreach ($rs as $key => $value) {
        if (empty($value))
            echo $key . "&nbsp;&nbsp;";
        else
            echo "<a href=\"$value\">$key</a>&nbsp;&nbsp;";
    }
} else {
    echo "  ";
} 

?>

</div>

<div class="linksfooter">
<?php include "links.html"; ?>
</div>

<div id="footer"> 
<?php include "tags.html" ?>
</div>

</div>
</div>

 <p align="center">
    <a target="_blank" href="http://validator.w3.org/check?uri=referer"><img
        src="http://www.w3.org/Icons/valid-xhtml10"
        alt="Valid XHTML 1.0 Transitional" height="31" width="88" border="0" /></a>
  </p> 

</body>
</html>
<?php

class page_spilt
{
    var $pagename = 'Page'; //       
    var $last = ""; //          
    var $next = ""; //        
    var $perv = ""; //   
    var $frst = ""; // 
    var $lastdiable = "<a></a>";
    var $nextdiable = "<a></a>";
    var $pervdiable = "<a></a>";
    var $frstdiable = "<a></a>"; //   
    var $resperonetime = 25; //       
    var $limitnumbersperonetime = 11;
    var $char = "...";

    ////////////////////////////////////////////////////////////////////
    /*        */
    var $pageNumber = 1;
    var $totalresnumber;
    var $rsfrom;
    var $rsto;
    var $querystring = ''; // example id=1&e=2&r=5 //       
    var $SQLquerystring;
    var $totalpages;


    function page_spilt($query, $page = "")
    {
        $page = intval($page);
        if (empty($page))
            $page = 1;
        $this->pageNumber = $page; #################
        $this->SQLquerystring = $query;
        $query = $this->query($query);
        $this->totalresnumber = mysql_num_rows($query); #################
        $this->totalpages = ceil($this->totalresnumber / $this->resperonetime);
    }

    function get_results()
    {
        if (empty($this->SQLquerystring))
            return false;
        $limit = ($this->pageNumber - 1) * $this->resperonetime;
        $this->rsfrom = $limit + 1;
        $this->rsto = $this->rsfrom + $this->resperonetime - 1;
        if ($this->rsto > $this->totalresnumber)
            $this->rsto = $this->totalresnumber;
        $SQL = $this->SQLquerystring . " LIMIT " . $limit . "," . $this->resperonetime;
        $rs = $this->select($SQL);
        if (is_array($rs))
            return $rs;
        else
            return false;
    }

    function get_numbers()
    {
        $URl = empty($this->querystring) ? $_SERVER["PHP_SELF"] . "?" . $this->pagename .
            "=" : $_SERVER["PHP_SELF"] . "?" . $this->querystring . "&" . $this->pagename .
            "=";
        if ($this->pageNumber == 1) {
            $pagecounter[$this->frstdiable] = "";
            $pagecounter[$this->pervdiable] = "";
        } else {
            $pagecounter[$this->frst] = $URl . "1";
            $pagecounter[$this->perv] = $URl . ($this->pageNumber - 1);
        }
        if ($this->totalpages > $this->limitnumbersperonetime) {
        	if($this->pageNumber<6) $start = 1; else $start= $this->pageNumber-5;
        	if(($this->pageNumber+($this->limitnumbersperonetime-6))>$this->totalpages) $end = $this->totalpages; else $end = $this->pageNumber+($this->limitnumbersperonetime-6);
         for ($i = $start; $i <= $end; $i++) {
                $pagecounter[$i] = $URl . $i;
            }
            if($end!=$this->totalpages) 
             $pagecounter[$this->char] = "";
        } else {
            for ($i = 1; $i <= $this->totalpages; $i++) {
                $pagecounter[$i] = $URl . $i;
            }
        }

        if ($this->pageNumber == $this->totalpages) {
            $pagecounter[$this->lastdiable] = "";
            $pagecounter[$this->nextdiable] = "";
        } else {
            $pagecounter[$this->next] = $URl . ($this->pageNumber + 1);
            $pagecounter[$this->last] = $URl . $this->totalpages;
        }
        return $pagecounter;
    }

    //Function for sql query
    function print_error($sql)
    {
        $message = '<p align="right" dir="rtl">MySQL Error ' . mysql_errno();
        $message .= '<br/>SQL: ' . $sql;
        $message .= '<br/>MySQL said: ' . mysql_error() . '</p>';
        echo $message;
    }

    //function used to query db
    function query($sql)
    {
        //echo $sql."<BR />\n";
        $rs = mysql_query($sql);
        if (!$rs) {
            $this->print_error($sql);
        }
        return $rs;
    }

    //function will return array of selected data
    function select($sql)
    {
        $rs = $this->query($sql);
        if (!$rs) {
            return;
        }

        @$num_rows = mysql_numrows($rs);

        if (($rs) && ($num_rows > 0)) {

            $data_array = array();
            while ($row = mysql_fetch_row($rs)) {
                $data_array[] = $row;
            }
            // Free the result
            mysql_free_result($rs);

            return $data_array;
        } else {
            return false;
        }
    }
}
?>
2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by -==Zero==-
0

How about:

$categoryId = 22;

$split = new page_split;
$split->querystring = "id={$categoryId}";

// The call the other page_split functions afterwards...

R.

0

How about:

$categoryId = 22;

$split = new page_split;
$split->querystring = "id={$categoryId}";

// The call the other page_split functions afterwards...

R.

Is This Work For All Categories ??

I need To make It Work For All Categories Not Just Id 22

1

When the category page loads, get the id and set the querystring variable of the pagination class. E.g:

<?php // cat.php

$categoryId = (int)$_GET['id'];

$split = new page_split;
$split->querystring = "id={$categoryId}";

// Perform the rest of the page functionality...

Does that make sense?

R.

Votes + Comments
Thanks So Much :) Solved
0

This Is The Full Code

Could You Plz Tell me Where To Put Your Code

Or If U Can Edit It Plz

<?php

include('func.php');

$id = intval($_GET["id"]);
$Sql2 = mysql_query("select id,name from ads_cat where id='$id'");
$Row2 = @mysql_fetch_array($Sql2);
if (!$Row2)
{
Echo "<meta http-equiv='Refresh' content='0;URL=Error.php'>";
exit;
}

$headers = headers("tabs.html");
$headers = str_replace("{menu}",menu(),$headers);

echo $headers;

?>

<div class="content"> 
<br/>
<?php

require_once 'split.php';

$split = new page_spilt("SELECT `id`,`title`,`full` FROM `ads` where cat='$id' AND active='0' 

ORDER BY `id` DESC", $_GET["p"]);
$rs = $split->get_results();
if (is_array($rs)) {
    foreach ($rs as $key => $value) {
echo "<div style='width: 186px; height: 174px; float:right; background: transparent url

(Zimg/Box.A.Png) no-repeat; padding: 0 4.5px 10px 0px'>"; 
echo "<table width='98%' border='0'>";
echo "<tr>";
echo "<td class='x1'>" . $rs[$key][1] . "</td>";
echo "</tr>";
echo  "<tr>";
echo "<td class='x2'>" . $rs[$key][2] . "</td>";
echo "</tr>";
echo "<tr>
<td><a class='x3' target='_blank' href='details.php?id=". $rs[$key][0]."'>تفاصيل</a>
</td>
</tr>";
echo "</table>";
echo "</div>";
    }

?>
0

Thank You So Much I Got It

The Code Should Be Like This

<?php

require_once 'split.php';

$split = new page_spilt("SELECT `id`,`title`,`full` FROM `ads` where cat='$id' AND active='0' 

ORDER BY `id` DESC", $_GET["Page"]);
$split->querystring = "id=$id"; 
$rs = $split->get_results();
if (is_array($rs)) {
    foreach ($rs as $key => $value) {
echo "<div style='width: 186px; height: 174px; float:right; background: transparent url

(Zimg/Box.A.Png) no-repeat; padding: 0 4.5px 10px 0px'>"; 
echo "<table width='98%' border='0'>";
echo "<tr>";
echo "<td class='x1'>" . $rs[$key][1] . "</td>";
echo "</tr>";
echo  "<tr>";
echo "<td class='x2'>" . $rs[$key][2] . "</td>";
echo "</tr>";
echo "<tr>
<td><a class='x3' target='_blank' href='details.php?id=". $rs[$key][0]."'>تفاصيل</a>
</td>
</tr>";
echo "</table>";
echo "</div>";
    }

?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.