PHP Numaralandırma ile ilgili sorun

0 Cevap php

Benim koduyla bir sorun (üzgünüm onun çok, ama seni, bir tablodan onun temelde sadece bir deyim göstermek biliyordu onun tek yolu) bir sayfa bağlantısını gösterir, ancak sayfa sonuç değişmez yaşıyorum. Temelde sayfa başına 1 sonuç örneğin ayarlamak ama tüm sonuçlarını gösterir, ancak hala bir sonraki sayfaya gitmek için üst kısmında bir bağlantı gösterir. Sonraki sayfa sadece aynı gösterir. Ben bir PHP acemi yüzden herhangi bir yardım büyük mutluluk duyacağız değilim.

Teşekkürler!

<?php

            if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1;
            $max_results = 1;
            $from = (($page * $max_results) - $max_results);
            REQUIRE('config.php');
            $q = mysql_real_escape_string(ucfirst(trim($_REQUEST['q'])));
            $result = mysql_query("SELECT * FROM gj WHERE name LIKE '%$q%' OR cat1 LIKE '%$q%' OR cat2 LIKE '%$q' OR cat3 LIKE '%$q' ORDER by name") or trigger_error(mysql_error());
            $rows = mysql_num_rows($result);
            if($rows == 0){

            }
            echo " <div id='title'>Search for &quot;$q&quot;<div class='righttitle'>$rows business";if($rows > 1){echo "es";}elseif($rows == "0"){echo "es";}echo" found";
            echo"<div id='pagenumbers'>";
            // (1) get the total number of results for your query
            // modify this to match the total results for the main query
            $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM gj where name LIKE '%$q%' OR cat1 LIKE '%$q%' OR cat2 LIKE '%$q' OR cat3 LIKE '%$q'"),0); 

            // (2) Calculate total number of pages. Round up using ceil()
            $total_pages = ceil($total_results / $max_results); 

            if($total_results > $max_results)
            {
              // (3) build Previous link
              if($page > 1)
              {
                 $prev = ($page - 1);
                 echo "<a href=\"".$_SERVER['PHP_SELF']."?q=$q&page=$prev\">&lt;&lt; Prev</a> ";
              } 

              // (4) display page numbers
              for($i = 1; $i <= $total_pages; $i++)
              {
                 if($page == $i)
                 {
                    echo $i . " ";
                 }
                 else
                 {
                    echo "<a href=\"".$_SERVER['PHP_SELF']."?q=$q&page=$i\">$i</a> ";
                 }
              } 

              // (5) build Next Link
              if($page < $total_pages)
              {
                   $next = ($page + 1);
                   echo "<a href=\"".$_SERVER['PHP_SELF']."?q=$q&page=$next\">Next &gt;&gt;</a>";
              }
            }

  echo"</div></div></div>";
        while($row = mysql_fetch_array($result))
        {
        $id=$row['id'];
        $name=$row['name'];
        $phone=$row['phone'];
        $website=$row['website'];
        $city=$row['city'];
        $address=$row['address1'];
        $zipcode=$row['zipcode'];
        $sponsored = $row['sponsored'];
        $addressmap = preg_replace('/\s/', '+',$address);
        $citymap = preg_replace('/\s/', '+',$city);
        //Start While Loop
        echo"
        <div id='listing'>
            <div id='mainlisting'>";
            echo"
                <div class='name'>
                    <a href='./more.php?id=$id' class='";if($sponsored != 1){echo "red";}else{echo"sponsored";}echo"'>$name</a> <div class='right'>$phone</div>
                </div>
                <div class='other'>
                    $address, $city, CO $zipcode 
|<a  target='_blank' href='http://maps.google.com/maps?        f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=$addressmap,+$city+CO&amp;&amp;&amp;ie=UTF8&amp;hq=&amp;hnear=$address,+$city,+Colorado+$zipcode&amp;safe=active&amp;&amp;&amp;t=h&amp;z=14&amp;iwloc=A&amp;output=embed' rel='lyteframe' class='";if($sponsored != 1){echo "red";}else{echo"sponsored";}echo"' title='$name' rev='width: 500px; height: 500px; scrolling: no;'> See Map</a><br/>
                    <a href='#' class='";if($sponsored != 1){echo "red";}else{echo"sponsored";}echo"'>";if($website != null){ echo "<a target='_blank' href='$website' class='";if($sponsored != 1){echo "red";}else{echo"sponsored";}echo"'>Website</a> |";}echo" <a href='#' class='";if($sponsored != 1){echo "red";}else{echo"sponsored";}echo"'>More Info</a>
                </div>
            </div>
        </div><!--/LISTING-->";

        }

Michael, ben ne yaptığını denedim ama yanlış yapmış olabilir ... Burada nerede deyimi önce benim kodudur

    <?php
        $page = 1; $total_pages = 9; $record_start = ($page * $total_pages) - $total_pages; 
            REQUIRE('config.php');
            $q = mysql_real_escape_string(ucfirst(trim($_REQUEST['q'])));
            $result = mysql_query("SELECT * FROM gj WHERE name LIKE '%$q%' OR cat1 LIKE '%$q%' OR cat2 LIKE '%$q' OR cat3 LIKE '%$q' ORDER by name  LIMIT 0,9") or trigger_error(mysql_error());
            $rows = mysql_num_rows($result);
            if($rows == 0){

            }
            echo " <div id='title'>Search for &quot;$q&quot;<div class='righttitle'>$rows business";if($rows > 1){echo "es";}elseif($rows == "0"){echo "es";}echo" found";
            echo"<div id='pagenumbers'>";
            // (1) get the total number of results for your query
            // modify this to match the total results for the main query
            $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM gj where name LIKE '%$q%' OR cat1 LIKE '%$q%' OR cat2 LIKE '%$q' OR cat3 LIKE '%$q '"),0); 

            // (2) Calculate total number of pages. Round up using ceil()
            $alltotal_pages = ceil($total_results / $max_results); 

            if($total_results > $max_results)
            {
              // (3) build Previous link
              if($page > 1)
              {
                 $prev = ($page - 1);
                 echo "<a href=\"".$_SERVER['PHP_SELF']."?q=$q&page=$prev\">&lt;&lt; Prev</a> ";
              } 

              // (4) display page numbers
              for($i = 1; $i <= $alltotal_pages; $i++)
              {
                 if($page == $i)
                 {
                    echo $i . " ";
                 }
                 else
                 {
                    echo "<a href=\"".$_SERVER['PHP_SELF']."?q=$q&page=$i\">$i</a> ";
                 }
              } 

              // (5) build Next Link
              if($page < $alltotal_pages)
              {
                   $next = ($page + 1);
                   echo "<a href=\"".$_SERVER['PHP_SELF']."?q=$q&page=$next\">Next &gt;&gt;</a>";
              }
            }

"echo";

0 Cevap