Announcement

Collapse
No announcement yet.

Need help writing a Search script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help writing a Search script

    I have another program that uses MySQL and PHP to write 'FAQs' into the database. However, this program does not have a Search function. Can someone please write a Search script for me?

    Thanks,

    Aunt

  • #2
    Here's something to start with:

    PHP Code:
    <?php

    include("lib.inc.php"); // include the library

    if ($query == '') {
        print 
    "You did not enter a query, go back and enter a query.";
    } else {

        
    mysql_select_db("database");
        
    $search "SELECT * FROM table WHERE text LIKE '%$query%'";
        
    $result mysql_query($search);
        
    $found 0;
        for (
    $i=0$i<=mysql_num_rows($result)-1$i++) {
            
    $threadid mysql_result($result$i,"threadid");
            
    $forumid mysql_result($result$i,"forumid");
            
    $title mysql_result($result$i,"title");
            
    $user mysql_result($result$i"username");
            
    $email mysql_result($result,$i,"email");

            if (
    $title == '') {
                
    // do nothing, don't print it
            
    } else {
                echo 
    "$title - $user - $email<br>\n";            
            }
            
    $found++;
        }
        
        if (
    $found == 0) {
        echo 
    "Nothing matched your query: <b>$query</b>";
        } else {
        echo 
    "There "$found "were" "was"$found "$found "matches" "match" ," for your query: <b>$query</b>.";
        }
        
    mysql_free_result($result);
        
    }
    ?>
    [/PHP

    Try working with that and see what you can get.


    Hope this helps.
    -Vic

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...
    X