Results 1 to 6 of 6

Thread: PHP to search contents on web page

  1. #1
    Join Date
    Mar 2010
    Posts
    197

    PHP to search contents on web page

    Hello,
    I want to do a search on my site with a display page by page, my 1st problem is that I lost my application by changing the page and I also want to test whether my field "text" is empty.
    Here is my code
    Code:
    ?php 
    mysql_connect("Xxxx", Xxxxx, ") 
    mysql_select_db("Xxxxxx"); 
    
    classdbSearch 
    ( 
      / / Words and expressions to search
      private $ words; 
       
      / / Separator
      private $ September; 
       
      / / Search option
      private $ options; 
       
      / / Number of words
      private $ count_words; 
       
      / / Where clause
      private $ query_where=''; 
       
      publicfunction__construct($ Search_options, $ Search_text) 
    (
        $ This->query_prepared=1; 
         
        / / Search option
        $ This->option=$ Search_options; 
         
        / / Search AND
        if ($ This->option=='All') 
    (
          $ This->September='AND'; 
          $ This->option=1; 
          $ This->words=explode('', addslashes($ Search_text)); 
          $ This->count_words=count($ This->words); 
    )
        / / OR search
        else if ($ This->option=='One') 
    (
          $ This->September='OR'; 
          $ This->option=2; 
          $ This->words=explode('', addslashes($ Search_text)); 
          $ This->count_words=count($ This->words); 
    )
        / / Exact phrase
        else 
    (
          $ This->option=0; 
          $ This->words[0] =addslashes($ Search_text); 
    ) 
    )

  2. #2
    Join Date
    Nov 2009
    Posts
    446

    Re: PHP to search contents on web page

    Hello,
    I think this is what you are looking for
    Code:
    $ sql = "SELECT * FROM table LIMIT $ str, $ paon"
    to adapt and look for the limits is simple:
    Code:
    $ sql = query ('table', array ('field1', 'field2'), 'id, champ4', 'id', 'DESC', $ limit_start, $ paging);
    still has the complete name of the table , fields, and set the application.
    I hope this will help you an you will make your code perfect

  3. #3
    Join Date
    Nov 2009
    Posts
    356

    Re: PHP to search contents on web page

    Hey
    Check out the following code, it may help you
    Code:
    <?php 
    func($ curpg, $ nb_pg, $ Link='? Page =% d', Around $=3, $ frslst=1) 
    (
      Paging $=''; 
    if (!ereg('% D', $ Link))$ Link.='% D'; 
    if ($ nb_pg>1 ) ( 
    
        / / Link previous
        if ($ curpg>1 ) 
          Paging $.='.sprintf($ Link, $ curpg-1).'"Title =" Previous Page ">' Back '; 
    else
          Paging $.=' <span class="prevnext disabled"> 'Back'; 
    
        / / Link (s) beginning
        for ($ I=1 ;$ I<=$ frslst;$ I+ +) ( 
          Paging $.=''; 
          Paging $.= ($ curpg==$ I)?' <span class="current"> '.$ I.'': '.sprintf($ Link, $ I).'">'.$ I.''; 
    )
    
        / / ... After the start pages?
        if (($ curpg-Around $)>$ frslst+1 ) 
          Paging $.='...'; 
    
        / / We loop around the current page
        $ Start= ($ curpg-Around $)>$ frslst?$ curpg-Around $: $ frslst+1; 
        $ End= ($ curpg+Around $) <= ($ nb_pg-$ frslst)?$ curpg+Around $: $ nb_pg-$ frslst; 
    for ($ I=$ Start;$ I<=$ End;$ I+ +) ( 
          Paging $.=''; 
    if ($ I==$ curpg) 
            Paging $.=' <span class="current"> '.$ I.''; 
    else
            Paging $.='.sprintf($ Link, $ I).'">'.$ I.''; 
    )
    
        / / ... Before nb_pages page?
        if (($ curpg+Around $) <$ nb_pg-$ frslst) 
          Paging $.='...'; 
    
        / / Link (s) end
        $ Start=$ nb_pg-$ frslst+1; 
    if ($ Start<=$ frslst)$ Start=$ frslst+1; 
    for ($ I=$ Start;$ I<=$ nb_pg;$ I+ +) ( 
          Paging $.=''; 
          Paging $.= ($ curpg==$ I)?' <span class="current"> '.$ I.'': '.sprintf($ Link, $ I).'">'.$ I.''; 
    )

  4. #4
    Join Date
    Nov 2009
    Posts
    518

    Re: PHP to search contents on web page

    Hello,
    For the counting of pages it can if you reference the application number of lines for your criteria. Look at the last argument of the function application. Currently your code you reference the count (*) section of your table, so all of your table. Effectively reloading by paging you do that references the offset of the page GET method when your application expects a function $ _POST ['search']. I guess you have understood what I am trying to explain here.

  5. #5
    Join Date
    Nov 2009
    Posts
    343

    Re: PHP to search contents on web page

    Hello,
    This is the syntax of the code, that is what your code should look like, take a look for you
    Code:
    function application ($ table, $ fields, $ select, $ order, $ direction, $ limit_start, $ limit_nb $ count ='') 
    ( 
    
    if (! empty ($ _POST ['search'])) 
    ( 
    / / option Search 
    $ option = $ _POST ['option'] 
    / / text search 
    $ search = $ _POST ['search'], 
    $ _SESSION ['password'] = $ search, 
    $ _SESSION ['option'] = $ option; 
    ) 
    else ( 
    $ search = $ _SESSION ['password'], 
    $ option = $ _SESSION ['option']; 
    )
    ......

  6. #6
    Join Date
    Dec 2009
    Posts
    23

    Re: PHP to search contents on web page

    This is not PHP script, but you may find this script useful. Just take the algorithm and put it into PHP.

    Biterscripting script SS_FindStr.txt. It's called as

    Code:
    script "SS_FindStr.txt" dir("/path/to/html pages") files("*.html") str("string to search")

    Lists all html pages that contain the search string. Searches subdirectories, etc. Lists each page, the line number and the line text wherever the search string is found.

    Similarly, script SS_FindRE.txt is for searching using regular expressions.

    I think one of the biter scripting sample scripts also shows how to build a search engine, but I don't have much experience with it.

Similar Threads

  1. How to Search Contents of Network Files and Folders
    By Madhulika in forum Networking & Security
    Replies: 6
    Last Post: 07-07-2014, 06:21 AM
  2. Replies: 5
    Last Post: 25-01-2011, 08:10 AM
  3. New Google Search Page
    By Maq.H in forum Technology & Internet
    Replies: 2
    Last Post: 19-05-2010, 07:29 AM
  4. Why I cannot search my page on Google?
    By Barsha in forum Technology & Internet
    Replies: 4
    Last Post: 11-03-2010, 03:48 AM
  5. Windows 7 search does not return file contents
    By Benedict in forum Operating Systems
    Replies: 3
    Last Post: 05-12-2009, 10:38 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,039,374.13530 seconds with 17 queries