اذهب إلى المحتوى
  • 0

مشكلة بخصوص ترقيم الصفحات pagination

Our World عالمنا

السؤال

$pageNum= isset($_GET['page']) && is_numeric($_GET['page']) ? intval($_GET['page']) : 1;
$adsPerPage=4;
$startFrom=($pageNum-1)* $adsPerPage;

عند استخدام الكود التالي بدون التحديد ( limit) يتم عرض كل الاعلانات مع وجود الترقيم باسفل ولكن وجوده كعدمه فعند الضغط على اى رقم (1,2,3)  يعرض كل الاعلانات

if ($category==0 && $subCategory==0 && $state==0 ) {
     $stmt=$conn->prepare(" SELECT *
                 FROM items
             join categories on categories.cat_id=items.CAT_ID
             join sub        on items.subcat_id=sub.subcat_id 
             JOIN country    ON items.country_id=country.country_id
             JOIN state      ON items.state_id=state.state_id
             JOIN city       ON items.city_id=city.city_id
             WHERE   country.country_id=? 
             AND items.NAME LIKE '%$inputSearch%' order by feature desc
             /*limit $startFrom,$adsPerPage*/");            
           
     $stmt->execute(array($country));
     $item= $stmt->fetchAll();

}

    

عند استخدام الكود نفسه مع التحديد ( limit) يعرض 4 اعلانات فقط ولا يعرض ترقيم هكذا:

if ($category==0 && $subCategory==0 && $state==0 ) {
     $stmt=$conn->prepare(" SELECT *
                 FROM items
             join categories on categories.cat_id=items.CAT_ID
             join sub        on items.subcat_id=sub.subcat_id 
             JOIN country    ON items.country_id=country.country_id
             JOIN state      ON items.state_id=state.state_id
             JOIN city       ON items.city_id=city.city_id
             WHERE   country.country_id=? 
             AND items.NAME LIKE '%$inputSearch%' order by feature desc
             limit $startFrom,$adsPerPage");              
           
     $stmt->execute(array($country));
     $item= $stmt->fetchAll();  

        }

$adsTotalNumber=count($item);     

$NumberOfPages=ceil($adsTotalNumber/$adsPerPage);

ايه حل المشكلة 

تم التعديل في بواسطة Adnane Kadri
تنسيق الشيفرة
رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

لا تظهر أي مشكلة بالشيفرة او بالاستعلام، فهذا هو المفترض ان يحدث في تصفيح العناصر من قواعد البيانات، فعدم استعمالك للاستعلام LIMIT لن يقوم بتحديد اي فهرس ابتدائي او عدد صفوف معين يتم اقتطاعه. وفي حالة اقتطاعه عن طريق تحديد الاستعلام بـ: 

LIMIT $startFrom, 4

سيتم جلب الأربع عناصر الموالية للفهرس المحددة. أليس هذا هو المراد من تصفيح المنتجات؟

ما المشكلة التي تواجهها تحديدا؟

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ 17 دقائق مضت قال Adnane Kadri:

لا تظهر أي مشكلة بالشيفرة او بالاستعلام، فهذا هو المفترض ان يحدث في تصفيح العناصر من قواعد البيانات، فعدم استعمالك للاستعلام LIMIT لن يقوم بتحديد اي فهرس ابتدائي او عدد صفوف معين يتم اقتطاعه. وفي حالة اقتطاعه عن طريق تحديد الاستعلام بـ: 


LIMIT $startFrom, 4

سيتم جلب الأربع عناصر الموالية للفهرس المحددة. أليس هذا هو المراد من تصفيح المنتجات؟

ما المشكلة التي تواجهها تحديدا؟

الـ $_GET المرسل من pagination  متعارض مع $_GET  اخر فى الصفحة عندما اضغط على رقم 2 فى ترقيم الصفحة يذهب الى صفحة بها منتجات من قسم اخر

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ 17 ساعات قال Our World عالمنا:

الـ $_GET المرسل من pagination  متعارض مع $_GET  اخر فى الصفحة عندما اضغط على رقم 2 فى ترقيم الصفحة يذهب الى صفحة بها منتجات من قسم اخر

هلا قمت بتحديد قيمتي المتغيرين NumberOfPages و adsTotalNumber من داخل شرط التحقق بدلا عن خارجه؟ يكون ذلك كـ: 

if ($category==0 && $subCategory==0 && $state==0 ) {
     $stmt=$conn->prepare(" SELECT *
                 FROM items
             join categories on categories.cat_id=items.CAT_ID
             join sub        on items.subcat_id=sub.subcat_id 
             JOIN country    ON items.country_id=country.country_id
             JOIN state      ON items.state_id=state.state_id
             JOIN city       ON items.city_id=city.city_id
             WHERE   country.country_id=? 
             AND items.NAME LIKE '%$inputSearch%' order by feature desc
             limit $startFrom,$adsPerPage");              
           
     $stmt->execute(array($country));
     $item= $stmt->fetchAll();  

$adsTotalNumber=count($item);     

$NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
}

ثم هل يمكنك تحديد بالضبط ما القيمتان المتعارضتان؟ 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ On 05/05/2022 at 18:18 قال Adnane Kadri:

هلا قمت بتحديد قيمتي المتغيرين NumberOfPages و adsTotalNumber من داخل شرط التحقق بدلا عن خارجه؟ يكون ذلك كـ: 


if ($category==0 && $subCategory==0 && $state==0 ) {
     $stmt=$conn->prepare(" SELECT *
                 FROM items
             join categories on categories.cat_id=items.CAT_ID
             join sub        on items.subcat_id=sub.subcat_id 
             JOIN country    ON items.country_id=country.country_id
             JOIN state      ON items.state_id=state.state_id
             JOIN city       ON items.city_id=city.city_id
             WHERE   country.country_id=? 
             AND items.NAME LIKE '%$inputSearch%' order by feature desc
             limit $startFrom,$adsPerPage");              
           
     $stmt->execute(array($country));
     $item= $stmt->fetchAll();  

$adsTotalNumber=count($item);     

$NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
}

ثم هل يمكنك تحديد بالضبط ما القيمتان المتعارضتان؟ 

هذه هي الاكواد لعل الصورة تتضح اكثر:

=====================================

الصفحة الرئيسية

<!----------------------------START CATEGORIES--------------------->
<span class="Choose-category latest-ads">Choose a category</span>
<section class="category-section">
    <?php
         if(!empty($cats)){
             foreach ($cats as $cat) {
                 ?> <div> <?php
                 if($cat['cat_id']==1){echo '<i class="fas fa-store"></i>';}
                 if($cat['cat_id']==2){echo '<i class="fas fa-tools"></i>';}
                 if($cat['cat_id']==3){echo '<i class="fas fa-shopping-bag"></i>';}
                 if($cat['cat_id']==4){echo '<i class="fas fa-store"></i>';}
                 if($cat['cat_id']==5){echo '<i class="fas fa-user-friends"></i>';}
                 if($cat['cat_id']==6){echo '<i class="fas fa-question-circle"></i>';}
                 echo "<a href='search.php?c=".$country."&i=".$cat['cat_id']."&n=".$cat['name']."' class='cat' value=".$cat['cat_id'].">".$cat['name']."</a>";
                 ?> </div> <?php
             }
         }
    ?>
</section>

================================

صفحة البحث

if( (isset($_GET['c']) && is_numeric($_GET['c']) &&  isset($_GET['i']) && is_numeric($_GET['i']) && isset($_GET['n']) && ($_GET['n']=='Activities' || $_GET['n']=='Jobs'||$_GET['n']=='Products/Services'||$_GET['n']=='Occasions'||$_GET['n']=='Wanted'||$_GET['n']=='Lost'))|| isset($_GET['page'] )   ) {
          $catid       =isset($_GET['i'])?$_GET['i']:''; //category id
          $catName     =isset($_GET['n'])?$_GET['n']:''; //category name
          $count       =isset($_GET['c'])?$_GET['c']:''; //country id
          $countryName ='';
         $country=$count<1||$count>4?1:$count;
         $category=$catid<1||$catid>6?0:$catid;
//================================
        // pagination
     echo 'pageNum='.     $pageNum= isset($_GET['page']) && is_numeric($_GET['page']) ? intval($_GET['page']) : 1;
        $adsPerPage=3;
     echo  '<BR>startFrom='. $startFrom=($pageNum-1)* $adsPerPage;
         //==============================
              //country & category are false
         if(($country<1 || $country>4) && ($category<1 || $category>6) ){
             $stmt=$conn->prepare(" 
                     SELECT count(item_id)
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id>0 and country.country_id=1
                       ");
                     
              $stmt->execute();
              $adsTotalNumber=$stmt->fetchColumn();
           echo    '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
           //get ads
           $stmt=$conn->prepare(" 
                     SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id>0 and country.country_id=1
                     limit $startFrom,$adsPerPage  ");
                     
              $stmt->execute();
              $item= $stmt->fetchAll();

              //country & category are true
         }elseif(($country>=1 && $country<=4) && ($category>=1 && $category<=6) ){
             $stmt=$conn->prepare(" 
                     SELECT count(item_id)
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id =? and country.country_id=? 
                       ");
                     
              $stmt->execute(array($category,$country));
              $adsTotalNumber=$stmt->fetchColumn();
           echo    '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                     SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id =? and country.country_id=? 
                     limit $startFrom,$adsPerPage  ");
                     
              $stmt->execute(array($category,$country));
              $item= $stmt->fetchAll();

              //country is true, category is false
         }elseif(($country>=1 && $country<=4) && ($category<1 || $category>6) ){
             $stmt=$conn->prepare(" 
                     SELECT count(item_id)
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id>0 and country.country_id=? 
                      ");
                     
              $stmt->execute(array($country));
              $adsTotalNumber=$stmt->fetchColumn();
           echo    '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                     SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id>0 and country.country_id=? 
                     limit $startFrom,$adsPerPage  ");
                     
              $stmt->execute(array($country));
              $item= $stmt->fetchAll();

              //country is false, category is true
         }elseif(($country<1 || $country>4) && ($category>=1 && $category<=6) ){
             $stmt=$conn->prepare(" 
                     SELECT count(item_id)
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id=? and country.country_id=1 
                     ");
                     
              $stmt->execute(array($category));
             echo  'adsTotalNumb='. $adsTotalNumber=$stmt->fetchColumn();
           echo    '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                     SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id=? and country.country_id=1 
                     limit $startFrom,$adsPerPage  ");
                     
              $stmt->execute(array($category));
              $item= $stmt->fetchAll();
         }
         

//===================start pagination=========================    
        $jumpForward=3;
         $jumpBackward=3;

if($NumberOfPages>1 ){     
    if(isset($_GET['page'])){
    echo '<span style="margin-left:35vw">page '.$_GET['page'].'</span>';}else{
        echo '<span style="margin-left:35vw">page 1</span>';
    }
 ?>
 <nav aria-label="Page navigation example" class="pagination-container">
      <ul class="pagination pagination-lg">

     <?php if(($pageNum-$jumpBackward)>=1 ){  //previous
     ?> <li class="page-item"><a class="page-link prev" href="?page=<?php echo ($pageNum-$jumpBackward)?>">Previous (-3)</a></li><?php
      }else{
      ?> <li class="page-item disabled"><a class="page-link">Previous</a></li><?php
      }
   
     ///**/
  for ($page=1; $page<= $NumberOfPages;  $page++) {  //for loop
    echo '<li class="page-item"><a class="page-link" href="search.php?page='. $page.'">'. $page.'</a></li>';
   }
  
    if(($pageNum+$jumpForward)<=$NumberOfPages ){  //next
    ?> <li class="page-item"> <a class="page-link next"  href="?page=<?php echo ($pageNum+$jumpForward)?>" >Next (+3)</a> </li><?php
}else{
   ?> <li class="page-item disabled"> <a class="page-link "   >Last</a> </li><?php
}
 ?>  
    </ul > 
</nav>
<?php
}


}

 

===================================

الصفحة التي تجلب الاعلانات بناء على كود الاجاكس

//GET COMING FROM SEARCH PAGE TO RETURN ITEMS BASD ON AJAX
if ( (isset($_GET['cat'])  || isset($_GET['sub']) || isset($_GET['country']) || isset($_GET['state']) || isset($_GET['city']) || isset($_GET['search']) ) || isset($_GET['page'] )    ) {
             $category    =$_GET['cat'];
             $subcat    =$_GET['sub'];
             $country=$_GET['country'];
             $state  =$_GET['state'];
             $city   =$_GET['city'];
             $search =$_GET['search'];
             echo 'pagenum='.     $pageNum= isset($_GET['page']) && is_numeric($_GET['page']) ? intval($_GET['page']) : 1;
        $adsPerPage=2;
        $startFrom=($pageNum-1)* $adsPerPage;

            if( $category>0 && $subcat==0 && $state==0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and categories.cat_id=? ");
              $stmt->execute(array($country,$category));
           echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
           echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //GET ADS
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and categories.cat_id=? 
                 limit $startFrom,$adsPerPage ");
              $stmt->execute(array($country,$category));
              $item= $stmt->fetchAll();


              }elseif( $category==0 && $subcat==0 && $state==0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=?  ");
              $stmt->execute(array($country));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //GET ADS
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? limit $startFrom,$adsPerPage ");
              $stmt->execute(array($country));
              $item= $stmt->fetchAll();

              }elseif( $category==0 && $subcat==0 && $state>0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=? ");
              $stmt->execute(array($country,$state));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
             echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
             //get ads
             $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=? ");
              $stmt->execute(array($country,$state));
              $item= $stmt->fetchAll();

              }elseif( $category==0 && $subcat==0 && $state>0 && $city>0){
                  $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                  and city.city_id=? ");
              $stmt->execute(array($country,$state,$city));
               echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
               echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                  and city.city_id=? ");
              $stmt->execute(array($country,$state,$city));
              $item= $stmt->fetchAll();

              }elseif( $subcat==0 && $state>0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=? 
                 and categories.cat_id=?");
              $stmt->execute(array($country,$state,$category));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=? 
                 and categories.cat_id=? limit $startFrom,$adsPerPage");
              $stmt->execute(array($country,$state,$category));
              $item=$stmt->fetchAll();


              }elseif( $subcat>0 && $state>0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and sub.subcat_id =?");
              $stmt->execute(array($country,$state,$subcat));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and sub.subcat_id =? limit $startFrom,$adsPerPage");
              $stmt->execute(array($country,$state,$subcat));
              $item=$stmt->fetchAll();


              }elseif( $subcat>0 && $state>0 && $city>0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and sub.subcat_id =? and city.city_id=?");
              $stmt->execute(array($country,$state,$subcat,$city));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and sub.subcat_id =? and city.city_id=? limit $startFrom,$adsPerPage");
              $stmt->execute(array($country,$state,$subcat,$city));
              $item=$stmt->fetchAll();

              }elseif( $subcat==0 && $state>0 && $city>0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and city.city_id=? and categories.cat_id=? ");
              $stmt->execute(array($country,$state,$city,$category));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and city.city_id=? and categories.cat_id=? limit $startFrom,$adsPerPage");
              $stmt->execute(array($country,$state,$city,$category));
              $item=$stmt->fetchAll();


              }elseif( $subcat==0 && $state==0 && $city>0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and city.city_id=? 
                 and categories.cat_id=?  ");
              $stmt->execute(array($country,$city,$category));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and city.city_id=? 
                 and categories.cat_id=?  limit $startFrom,$adsPerPage");
              $stmt->execute(array($country,$city,$category));
              $item=$stmt->fetchAll();


              }elseif( $subcat>0 && $state==0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and sub.subcat_id=?  ");
              $stmt->execute(array($country,$subcat));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
             echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
             //GET ADS
             $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and sub.subcat_id=? limit $startFrom,$adsPerPage ");
              $stmt->execute(array($country,$subcat));
              $item=$stmt->fetchAll();

//===================start pagination=========================  
       
       $jumpForward=3;
        $jumpBackward=3;
            
if($NumberOfPages>1 ){  
    if(isset($_GET['page'])){
    echo '<span style="margin-left:35vw">page '.$_GET['page'].'</span>';}else{
        echo '<span style="margin-left:35vw">page 1</span>';
    }
 ?>
 <nav aria-label="Page navigation example" class="pagination-container">
      <ul class="pagination pagination-lg">

     <?php if(($pageNum-$jumpBackward)>=1 ){  //previous
     ?> <li class="page-item"><a class="page-link prev" href="?page=<?php echo ($pageNum-$jumpBackward)?>">Previous (-3)</a></li><?php
      }else{
      ?> <li class="page-item disabled"><a class="page-link">Previous</a></li><?php
      }
   
     /*$page=max(1,$pageNum-5);$page<=min($pageNum+2,$NumberOfPages);$page++*/
  for ($page=1; $page<= $NumberOfPages;  $page++) {  //for loop
    echo   '<li class="page-item"><a class="page-link" href="search.php?page='. $page.'">'. $page.'</a></li>';
   }
  
    if(($pageNum+$jumpForward)<=$NumberOfPages ){  //next
    ?> <li class="page-item"> <a class="page-link next"  href="?page=<?php echo ($pageNum+$jumpForward)?>" >Next (+3)</a> </li><?php
}else{
   ?> <li class="page-item disabled"> <a class="page-link "   >Last</a> </li><?php
}
 ?>  
    </ul > 
</nav>
<?php
}


              }

 

 

 

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ 30 دقائق مضت قال Our World عالمنا:

هذه هي الاكواد لعل الصورة تتضح اكثر:

=====================================

الصفحة الرئيسية


<!----------------------------START CATEGORIES--------------------->
<span class="Choose-category latest-ads">Choose a category</span>
<section class="category-section">
    <?php
         if(!empty($cats)){
             foreach ($cats as $cat) {
                 ?> <div> <?php
                 if($cat['cat_id']==1){echo '<i class="fas fa-store"></i>';}
                 if($cat['cat_id']==2){echo '<i class="fas fa-tools"></i>';}
                 if($cat['cat_id']==3){echo '<i class="fas fa-shopping-bag"></i>';}
                 if($cat['cat_id']==4){echo '<i class="fas fa-store"></i>';}
                 if($cat['cat_id']==5){echo '<i class="fas fa-user-friends"></i>';}
                 if($cat['cat_id']==6){echo '<i class="fas fa-question-circle"></i>';}
                 echo "<a href='search.php?c=".$country."&i=".$cat['cat_id']."&n=".$cat['name']."' class='cat' value=".$cat['cat_id'].">".$cat['name']."</a>";
                 ?> </div> <?php
             }
         }
    ?>
</section>

================================

صفحة البحث


if( (isset($_GET['c']) && is_numeric($_GET['c']) &&  isset($_GET['i']) && is_numeric($_GET['i']) && isset($_GET['n']) && ($_GET['n']=='Activities' || $_GET['n']=='Jobs'||$_GET['n']=='Products/Services'||$_GET['n']=='Occasions'||$_GET['n']=='Wanted'||$_GET['n']=='Lost'))|| isset($_GET['page'] )   ) {
          $catid       =isset($_GET['i'])?$_GET['i']:''; //category id
          $catName     =isset($_GET['n'])?$_GET['n']:''; //category name
          $count       =isset($_GET['c'])?$_GET['c']:''; //country id
          $countryName ='';
         $country=$count<1||$count>4?1:$count;
         $category=$catid<1||$catid>6?0:$catid;
//================================
        // pagination
     echo 'pageNum='.     $pageNum= isset($_GET['page']) && is_numeric($_GET['page']) ? intval($_GET['page']) : 1;
        $adsPerPage=3;
     echo  '<BR>startFrom='. $startFrom=($pageNum-1)* $adsPerPage;
         //==============================
              //country & category are false
         if(($country<1 || $country>4) && ($category<1 || $category>6) ){
             $stmt=$conn->prepare(" 
                     SELECT count(item_id)
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id>0 and country.country_id=1
                       ");
                     
              $stmt->execute();
              $adsTotalNumber=$stmt->fetchColumn();
           echo    '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
           //get ads
           $stmt=$conn->prepare(" 
                     SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id>0 and country.country_id=1
                     limit $startFrom,$adsPerPage  ");
                     
              $stmt->execute();
              $item= $stmt->fetchAll();

              //country & category are true
         }elseif(($country>=1 && $country<=4) && ($category>=1 && $category<=6) ){
             $stmt=$conn->prepare(" 
                     SELECT count(item_id)
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id =? and country.country_id=? 
                       ");
                     
              $stmt->execute(array($category,$country));
              $adsTotalNumber=$stmt->fetchColumn();
           echo    '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                     SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id =? and country.country_id=? 
                     limit $startFrom,$adsPerPage  ");
                     
              $stmt->execute(array($category,$country));
              $item= $stmt->fetchAll();

              //country is true, category is false
         }elseif(($country>=1 && $country<=4) && ($category<1 || $category>6) ){
             $stmt=$conn->prepare(" 
                     SELECT count(item_id)
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id>0 and country.country_id=? 
                      ");
                     
              $stmt->execute(array($country));
              $adsTotalNumber=$stmt->fetchColumn();
           echo    '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                     SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id>0 and country.country_id=? 
                     limit $startFrom,$adsPerPage  ");
                     
              $stmt->execute(array($country));
              $item= $stmt->fetchAll();

              //country is false, category is true
         }elseif(($country<1 || $country>4) && ($category>=1 && $category<=6) ){
             $stmt=$conn->prepare(" 
                     SELECT count(item_id)
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id=? and country.country_id=1 
                     ");
                     
              $stmt->execute(array($category));
             echo  'adsTotalNumb='. $adsTotalNumber=$stmt->fetchColumn();
           echo    '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                     SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                     FROM items
                     join sub on items.subcat_id=sub.subcat_id 
                     join categories on categories.cat_id=items.CAT_ID
                     JOIN country  ON items.country_id=country.country_id
                     JOIN state  ON items.state_id=state.state_id
                     JOIN city  ON items.city_id=city.city_id
                     where  categories.cat_id=? and country.country_id=1 
                     limit $startFrom,$adsPerPage  ");
                     
              $stmt->execute(array($category));
              $item= $stmt->fetchAll();
         }
         

//===================start pagination=========================    
        $jumpForward=3;
         $jumpBackward=3;

if($NumberOfPages>1 ){     
    if(isset($_GET['page'])){
    echo '<span style="margin-left:35vw">page '.$_GET['page'].'</span>';}else{
        echo '<span style="margin-left:35vw">page 1</span>';
    }
 ?>
 <nav aria-label="Page navigation example" class="pagination-container">
      <ul class="pagination pagination-lg">

     <?php if(($pageNum-$jumpBackward)>=1 ){  //previous
     ?> <li class="page-item"><a class="page-link prev" href="?page=<?php echo ($pageNum-$jumpBackward)?>">Previous (-3)</a></li><?php
      }else{
      ?> <li class="page-item disabled"><a class="page-link">Previous</a></li><?php
      }
   
     ///**/
  for ($page=1; $page<= $NumberOfPages;  $page++) {  //for loop
    echo '<li class="page-item"><a class="page-link" href="search.php?page='. $page.'">'. $page.'</a></li>';
   }
  
    if(($pageNum+$jumpForward)<=$NumberOfPages ){  //next
    ?> <li class="page-item"> <a class="page-link next"  href="?page=<?php echo ($pageNum+$jumpForward)?>" >Next (+3)</a> </li><?php
}else{
   ?> <li class="page-item disabled"> <a class="page-link "   >Last</a> </li><?php
}
 ?>  
    </ul > 
</nav>
<?php
}


}

 

===================================

الصفحة التي تجلب الاعلانات بناء على كود الاجاكس


//GET COMING FROM SEARCH PAGE TO RETURN ITEMS BASD ON AJAX
if ( (isset($_GET['cat'])  || isset($_GET['sub']) || isset($_GET['country']) || isset($_GET['state']) || isset($_GET['city']) || isset($_GET['search']) ) || isset($_GET['page'] )    ) {
             $category    =$_GET['cat'];
             $subcat    =$_GET['sub'];
             $country=$_GET['country'];
             $state  =$_GET['state'];
             $city   =$_GET['city'];
             $search =$_GET['search'];
             echo 'pagenum='.     $pageNum= isset($_GET['page']) && is_numeric($_GET['page']) ? intval($_GET['page']) : 1;
        $adsPerPage=2;
        $startFrom=($pageNum-1)* $adsPerPage;

            if( $category>0 && $subcat==0 && $state==0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and categories.cat_id=? ");
              $stmt->execute(array($country,$category));
           echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
           echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //GET ADS
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and categories.cat_id=? 
                 limit $startFrom,$adsPerPage ");
              $stmt->execute(array($country,$category));
              $item= $stmt->fetchAll();


              }elseif( $category==0 && $subcat==0 && $state==0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=?  ");
              $stmt->execute(array($country));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //GET ADS
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? limit $startFrom,$adsPerPage ");
              $stmt->execute(array($country));
              $item= $stmt->fetchAll();

              }elseif( $category==0 && $subcat==0 && $state>0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=? ");
              $stmt->execute(array($country,$state));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
             echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
             //get ads
             $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=? ");
              $stmt->execute(array($country,$state));
              $item= $stmt->fetchAll();

              }elseif( $category==0 && $subcat==0 && $state>0 && $city>0){
                  $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                  and city.city_id=? ");
              $stmt->execute(array($country,$state,$city));
               echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
               echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                  and city.city_id=? ");
              $stmt->execute(array($country,$state,$city));
              $item= $stmt->fetchAll();

              }elseif( $subcat==0 && $state>0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=? 
                 and categories.cat_id=?");
              $stmt->execute(array($country,$state,$category));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=? 
                 and categories.cat_id=? limit $startFrom,$adsPerPage");
              $stmt->execute(array($country,$state,$category));
              $item=$stmt->fetchAll();


              }elseif( $subcat>0 && $state>0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and sub.subcat_id =?");
              $stmt->execute(array($country,$state,$subcat));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and sub.subcat_id =? limit $startFrom,$adsPerPage");
              $stmt->execute(array($country,$state,$subcat));
              $item=$stmt->fetchAll();


              }elseif( $subcat>0 && $state>0 && $city>0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and sub.subcat_id =? and city.city_id=?");
              $stmt->execute(array($country,$state,$subcat,$city));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and sub.subcat_id =? and city.city_id=? limit $startFrom,$adsPerPage");
              $stmt->execute(array($country,$state,$subcat,$city));
              $item=$stmt->fetchAll();

              }elseif( $subcat==0 && $state>0 && $city>0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and city.city_id=? and categories.cat_id=? ");
              $stmt->execute(array($country,$state,$city,$category));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and state.state_id=?
                 and city.city_id=? and categories.cat_id=? limit $startFrom,$adsPerPage");
              $stmt->execute(array($country,$state,$city,$category));
              $item=$stmt->fetchAll();


              }elseif( $subcat==0 && $state==0 && $city>0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and city.city_id=? 
                 and categories.cat_id=?  ");
              $stmt->execute(array($country,$city,$category));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
              echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
              //get ads
              $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and city.city_id=? 
                 and categories.cat_id=?  limit $startFrom,$adsPerPage");
              $stmt->execute(array($country,$city,$category));
              $item=$stmt->fetchAll();


              }elseif( $subcat>0 && $state==0 && $city==0){
                  $stmt=$conn->prepare(" 
                 SELECT count(item_id)
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and sub.subcat_id=?  ");
              $stmt->execute(array($country,$subcat));
              echo  'adsTotalNumber'. $adsTotalNumber=$stmt->fetchColumn();
             echo '<br>NumberOfPa='.  $NumberOfPages=ceil($adsTotalNumber/$adsPerPage);
             //GET ADS
             $stmt=$conn->prepare(" 
                 SELECT sub.*,categories.*,items.*,country.*,state.*,city.*
                 FROM items
                 join categories on categories.cat_id=items.CAT_ID
                 join sub on items.subcat_id=sub.subcat_id 
                 JOIN country  ON items.country_id=country.country_id
                 JOIN state  ON items.state_id=state.state_id
                 JOIN city  ON items.city_id=city.city_id
                 where    country.country_id=? and sub.subcat_id=? limit $startFrom,$adsPerPage ");
              $stmt->execute(array($country,$subcat));
              $item=$stmt->fetchAll();

//===================start pagination=========================  
       
       $jumpForward=3;
        $jumpBackward=3;
            
if($NumberOfPages>1 ){  
    if(isset($_GET['page'])){
    echo '<span style="margin-left:35vw">page '.$_GET['page'].'</span>';}else{
        echo '<span style="margin-left:35vw">page 1</span>';
    }
 ?>
 <nav aria-label="Page navigation example" class="pagination-container">
      <ul class="pagination pagination-lg">

     <?php if(($pageNum-$jumpBackward)>=1 ){  //previous
     ?> <li class="page-item"><a class="page-link prev" href="?page=<?php echo ($pageNum-$jumpBackward)?>">Previous (-3)</a></li><?php
      }else{
      ?> <li class="page-item disabled"><a class="page-link">Previous</a></li><?php
      }
   
     /*$page=max(1,$pageNum-5);$page<=min($pageNum+2,$NumberOfPages);$page++*/
  for ($page=1; $page<= $NumberOfPages;  $page++) {  //for loop
    echo   '<li class="page-item"><a class="page-link" href="search.php?page='. $page.'">'. $page.'</a></li>';
   }
  
    if(($pageNum+$jumpForward)<=$NumberOfPages ){  //next
    ?> <li class="page-item"> <a class="page-link next"  href="?page=<?php echo ($pageNum+$jumpForward)?>" >Next (+3)</a> </li><?php
}else{
   ?> <li class="page-item disabled"> <a class="page-link "   >Last</a> </li><?php
}
 ?>  
    </ul > 
</nav>
<?php
}


              }

 

من الصعب جدا فحص كامل هاته الشيفرة وتحديد المشكلة بالضبط. 

قد أشرت الى تعارض بين قيمتين سابقا، هل يمكنك تحديد بالضبط ما القيمتان المتعارضتان؟ 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ 28 دقائق مضت قال Adnane Kadri:

من الصعب جدا فحص كامل هاته الشيفرة وتحديد المشكلة بالضبط. 

قد أشرت الى تعارض بين قيمتين سابقا، هل يمكنك تحديد بالضبط ما القيمتان المتعارضتان؟ 

التعارض هو "عند الضغط على اللينك الموجود فى الترقيم بدءا من الصفحة الثانية (234) المفترض ان يكمل باقى الاعلانات التى عرض جزء منها فى الصفحة الاولى؛ ولكن ما يحدث هو انه يحولني الى قسم "all categories"  ويعرض كل الاعلانات موزععة على صفحات الترقيم بدلا من عرض اعلانات القسم الذي اخترته 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

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

×   جرى استعادة المحتوى السابق..   امسح المحرر

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

  • إعلانات

  • تابعنا على



×
×
  • أضف...