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 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2009
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts

    all db entries on main search page

    Hi,

    I created a page for my dictionary search. But the problem is when I open the page I see all the words / vocabulary as a list under my search box. How can I fix this?


    and also, how can I add a script to show a message like "please write a word in order to search" if someone seeks sth without writing sth in the box.

    regards

    my codes are:

    Code:
    $search=$_POST["search"];
    
    $result = $result = mysql_query("SELECT * FROM dictionary WHERE tr LIKE  '%$search%' OR it LIKE '%$search%'");
    while($r=mysql_fetch_array($result))
    {    
       $tr=$r["tr"];
       $it=$r["it"];
       $id=$r["id"];
    
       //the result goes here.
    
    if ($search==$it){
         echo "$it = $tr";
    } else {
        echo "$tr = $it";
    } 
         echo "<a href=".$url.">".$url."</a><br>";
    }
    
    if ($id==0){
      echo "No record for that search.";
    } 
    if ($search==""){
        echo "Please write down a word to look for.";
    }
     
    ?>

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    PHP Code:
    if(isset($_POST["submitButtonName"])) //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EDIT
    {
        
    $search $_POST["search"];
        if(!empty(
    $search))
        {
            
    $result $result mysql_query("SELECT * FROM dictionary WHERE tr LIKE  '%$search%' OR it LIKE '%$search%'");
            if(
    mysql_num_rows($result)!=0)
            {
                while(
    $r=mysql_fetch_array($result))
                {    
                   
    $tr=$r["tr"];
                   
    $it=$r["it"];
                   
    $id=$r["id"];
                   
    //the result goes here.
                    
    if ($search==$it)
                    {
                         echo 
    "$it = $tr";
                    } 
                    else 
                    {
                        echo 
    "$tr = $it";
                    } 
                    echo 
    "<a href=".$url.">".$url."</a><br>";
                }
            }
            else
            {
                echo 
    "No record for that search.";
            }
        }
        else
        {
            echo 
    "Please write down a word to look for.";
        }


  • Users who have thanked Phil Jackson for this post:

    may_bailey (08-28-2009)

  • #3
    New Coder
    Join Date
    Aug 2009
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks a lot for your reply Phil,
    But I get an error like:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/bailey/public_html/search_result.php on line 43
    No record for that search.


    and I think the line 43 is here:

    Code:
     $result = $result = mysql_query("SELECT * FROM dictionary WHERE tr LIKE  '%$search%' OR it LIKE '%$search%'");
            if(mysql_num_rows($result)!=0) -> I Think it's here <-
            {
                while($r=mysql_fetch_array($result))
                {
    How can I solve that?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You're assumption of the problem is correct for its location. Although odd, $a = $a = $b, is a valid syntax so you're just overwriting the result of $result with $result. Funny as that sounds.
    There is no error checking here, the problem is with you're query and / or connectivity.
    PHP Code:
    $result mysql_query("SELECT * FROM dictionary WHERE tr LIKE '%$search%' OR it LIKE '%$search%'") or die(mysql_error()); 
    Run that, it will tell you what is wrong with you're query or connection.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    may_bailey (08-28-2009)

  • #5
    New Coder
    Join Date
    Aug 2009
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts

    solved

    Thanks a lot Fou-Lu.
    When I try the thing you said I saw the reason. Wrong database name =D
    my inexperience


  •  

    Posting Permissions

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