Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    FL, USA
    Posts
    153
    Thanks
    13
    Thanked 0 Times in 0 Posts

    php search box form...

    I decided to do a search box following this php script http://php.about.com/od/phpwithmysql...p_search_3.htm which seems very simple, in my case I'm not using the options form only a simple search box, and the visitors will be searching for articles, but how should I go about input the article info on the table; I created a table called articles, with columns "name", "date", "description", "url"... my doubt is with the description column, should I enter the whole article in there, the first lines or a descriptive content about that specific article, it seemed to me that entering the whole content would take sometime, although there are tools to do bulk insert into mysql....I want that when users search they get back the title of the article with at least the first 2 or 3 lines, the date, and the url... yes, yes I know this can be done with google

    any help appreciated

    www.pctechtips.org
    Last edited by mia_tech; 08-05-2008 at 12:55 AM.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    I would hardcode the entire article in your script, it'd be too much on the database to pull out a whole page of text out.

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    FL, USA
    Posts
    153
    Thanks
    13
    Thanked 0 Times in 0 Posts
    I'm just trying to get an idea how this is done..... how could I hard code the articles in the script... hint :0)


    thanks

    www.pctechtips.org

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Location
    FL, USA
    Posts
    153
    Thanks
    13
    Thanked 0 Times in 0 Posts
    I came up with my own search script the one found on the link above didn't quite worked for me, but still have a problem... and is that no matter what I search for I'm getting the whole content of the table back and the problem is on the sql string which I'm using
    Code:
    SELECT * FROM articles
    and I realize that I should be using some sort of condition on my sql statement to match the user search, but I can put it into php terms if someone could give a hand....here the php code
    PHP Code:
    <?php
    //open connection
    $conn mysql_connect("localhost""root""password") or die(mysql_error());
    //select database
    mysql_select_db("test"$conn);
    //the sql statement
    $sql "SELECT * FROM articles";
    //execute the statement
    $data mysql_query($sql$conn) or die(mysql_error());
    while (
    $result mysql_fetch_array($data)) {
        
    //giving names to the fields
        
    $title $result['title'];
        
    $date $result['date'];
        
    $info $result['info'];
        
    $url $result['url'];
        
    //put the results on the screen
        
    echo "<b>$title</b>";
        echo 
    " ";
        echo 
    "<b>$date</b><br>";
        echo 
    "$info<br>";
        echo 
    "$url<br>";
    }
    ?>
    and here is the search form
    Code:
    <h2>Search</h2>
    <form name="search" method="post" action="search1.php">
    Seach for: <input type="text" name="find" /> 
    <input type="submit" name="search" value="Search" />
    </form>
    thanks

    www.pctechtips.org


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •