Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Search results page navigation
Old 06-27-2006, 06:33 AM Search results page navigation
Super Talker

Posts: 145
Trades: 0
Hello ,

I have developed a web page that includes a search engine that search in the database and find items that includes the keyword that the user typed and displays the results. The results(the image of every item) are displayed in 4 columns and 4 rows(totally 16 items) and if they are more that 16 it goes to the next page and if are more than 32 it goes to the next page.The user can navigate to the first ,second, third or as many pages as there are the results.
For example: search results page 1/2/3/4

item1 item2 item3 item4
item5 item6 item7 item8
item9 item10 item11 item12
item13 item14 item15 item16

if user select the search result for page 2

item17 item18 item19 item20
item21 item22 item23 item24
item25 item26 item27 item28
item29 item30 item31 item32

the same for the rest of the pages

I have manage to display the correct results in 4 columns and 4 rows but the problem i have and i need your help is regariding the navigation in the next or previous page.

Here is my existing code:

The code for the form that has the search
HTML Code:
<form name="form1" method="post" action="search_term.php" >
                <input name="search" type="text" id="search">
                <input type="submit" name="Submit" value="GO">
        </form>
PHP Code:
<!-- display the results from the search -->
          <table width="133"  border="0" align="left" cellspacing="2">
           <?  
           
           $sqlcolour 
"Select * from Items where title like '%$title%' or description like '%$title%' order by Items.itemID limit 16";
          




$rsProducts =mysql_query($sqlcolour);

                         
$p=0;
 echo 
"<TR>";

while (
$row mysql_fetch_assoc($rsProducts)) {

  
$itemID=mysql_result($rsProducts,$p,"itemID");
  
$ref=mysql_result($rsProducts,$p,"ref");
  
$image=mysql_result($rsProducts,$p,"image");
  
$title=mysql_result($rsProducts,$p,"title");
  
$category_name=mysql_result($rsProducts,$p,"category_name");
  
$categoryID=mysql_result($rsProducts,$p,"categoryID");
  
$description=mysql_result($rsProducts,$p,"description");
  
$price=mysql_result($rsProducts,$p,"price");
  
$available=mysql_result($rsProducts,$p,"available");
  
$matchA=mysql_result($rsProducts,$p,"matchA");
  
$matchB=mysql_result($rsProducts,$p,"matchB");
  
$matchC=mysql_result($rsProducts,$p,"matchC");
  
$stone=mysql_result($rsProducts,$p,"stone");
  
$metal=mysql_result($rsProducts,$p,"metal");

if (
$p && $p == 0) {

        echo 
"</TR><TR>";
          }

 
 
  
?>
 
   
    <td width="47" height="53" align="center" class="bodytext">
     <form action="item_details.php" method="get" target="frame1">
       <input name='imageField' type='image'  src="images/small_images/small_<? echo  $image?>">
        <input name="itemID" type="hidden" value="<? echo $itemID?>">
    </form>       </td>
              <?
  $p
++;
  }
 
  
?>  
       
       </tr>
  </table>  
          
          
          <!--ends the search -->
I would realy appreciate your help in the problem.

Thanks,
Xenia
xenia is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-28-2006, 06:22 AM Re: Search results page navigation
Super Talker

Posts: 145
Trades: 0
Ok i manage to add some code and partially is working however I have a problem and I would appreciate if you could have a look to my code and suggest any solution. The problem I have is the following:

1)When I make a search it displays 0 / 1 where the 0 is a link, the number of page is: 1 and the maxpages is:2 and the address in the url
is http://domain.com/search_term.php

2)When I click on the 0 it displays 0 / 1 where the 1 is a link,the number of page :0 and the maxpages is :2 and the address in the url is
http://domain.com/search_term.php?ti...ection&&page=0

3)Now if i click on the 1 it displays the results of the first page ,displays 0 / 1 where the 0 is a link, the number of page is: 1 and the maxpages is:2 and the address in the url
http://domain.com/search_term.php?title=&&page=1

4)Now if i go to the url and change the number of the page to 2 it will display the rest of the results
ex.http://domain.com/search_term.php?title=&&page=2

and will also display 0 / 1 wher both are a link,if you click on the 0 it goes to the step 2 ,if you click on the 1 goes to the step 3. It displays also number of page :1 and the maxpages is :2

It is very strange and i think it might be just a small error and will work.

PHP Code:
          if (isset($_GET['page'])) {
               
$page $_GET['page'];
               echo 
"Page with value :"$page;
        }
        else {
             
$page 1;
             echo 
"\n if page is the first :"$page;
        }
           
$startlimit = ($page 1) * 16;
           echo 
"\n  startlimit :"$startlimit;

    

$SQL "SELECT
     COUNT(*) AS TotalItems
FROM
     Items
WHERE
     title LIKE '%
$key%' OR
     description LIKE '%
$key%'";
     


$r_results mysql_query $SQL );
$a_row mysql_fetch_array $r_results );
mysql_free_result $r_results );
$totalitems $a_row['TotalItems'];

echo 
"\n Total records: " $totalitems;
    
    
    
    
 
$sqlcolour "Select * from Items where title like '%$key%' or description like '%$key%' order by Items.itemID limit $startlimit, 16";
        
        echo 
"\n SQLcolour query: " $sqlcolour;




$rsProducts =mysql_query($sqlcolour);
                    
$p=0
 echo 
"<TR>";

while (
$row mysql_fetch_assoc($rsProducts)) {

  
$itemID=mysql_result($rsProducts,$p,"itemID");
  
$ref=mysql_result($rsProducts,$p,"ref");
  
$image=mysql_result($rsProducts,$p,"image");
  
$title=mysql_result($rsProducts,$p,"title");
  
$category_name=mysql_result($rsProducts,$p,"category_name");
  
$categoryID=mysql_result($rsProducts,$p,"categoryID");
  
$description=mysql_result($rsProducts,$p,"description");
  
$price=mysql_result($rsProducts,$p,"price");
  
$available=mysql_result($rsProducts,$p,"available");
  
$matchA=mysql_result($rsProducts,$p,"matchA");
  
$matchB=mysql_result($rsProducts,$p,"matchB");
  
$matchC=mysql_result($rsProducts,$p,"matchC");
  
$stone=mysql_result($rsProducts,$p,"stone");
  
$metal=mysql_result($rsProducts,$p,"metal");
  

if (
$p && $p == 0) {

        echo 
"</TR><TR>";
        }


  
  
?> 
HTML Code:
<td width="47" height="53" align="center" class="bodytext"> 
    <form action="item_details.php" method="get" target="frame1">
       <input name='imageField' type='image'  src="images/small_images/small_<? echo  $image; ?>">
       <input name="itemID" type="hidden" value="<? echo $itemID; ?>">
    </form>      </td>
PHP Code:
            <?
  $p
++;
  }
    
$maxpages ceil($totalitems 16);
    
    
   
for (
$k 0$k $maxpages$k++) {

     
$link '';
     
$linkpost '';
     
    
     if (
$page != $k) {
           
$link '<a href="' $_SERVER['PHP_SELF']. '?title=' $key .'&description='.$key.'&page=' $k .'">';
          
$linkpost '</a>'
        
     }
     echo 
$link $k $linkpost
     if (
$k != ($maxpages 1)) {
          echo 
' / ';
     }
}

  
?>
Thanks,
Xenia
xenia is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Search results page navigation
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11003 seconds with 12 queries