1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

php help please

Discussion in 'PHP' started by elina, Apr 14, 2011.

  1. elina

    elina New Member

    Joined:
    Apr 14, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    im very new to php. can anyone please help. im trying to create a search feature for my application which im using php and mysql. can you please give me the code for a simple search feature.

    thank you
     
  2. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    can you descripbe the search features
    if you clearly know the app, you can base your search on the DB itself, and dynamically generate the required links
    ex: you search for "best article"
    you have a page named best artcle in your DB
    you make link with the article ID
    hope you got it :D
     
  3. transparent

    transparent New Member

    Joined:
    May 5, 2011
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    blogger,online marketer, designer and a programmer
    Location:
    Redmond, Washington, United States
    Home Page:
    You need first to create a HTML form for the search

    HTML:
    <form action="search.php">
      <input type="text" name="s" />
      <input type="submit" value="Search" />
    </form>
    
    Now inside your search.php:
    PHP:
    <?php
    // connect to the database
    $con mysql_connect('localhost','username','password');
    mysql_select_db('database_name',$con);


    //create a search query
    $find $_REQUEST['s'];
    $q "SELECT * FROM `table_to_do_search` WHERE `field1` LIKE '%$find%' or `field2` LIKE '%$find%'";

    $result mysql_query($q);

    if(
    mysql_num_rows($result) > 0)
    {
      echo 
    '<h1>Results:</h1>';
      echo 
    '<ol>';
      while(
    $row mysql_fetch_assoc($result))
      {
         echo 
    '<li>'.$row['fieldname'].'</li>';
      }
      echo 
    '</ol>';

    }
    else
      echo 
    'No results found';

    ?>
    This is just a concept on how it should work.
     

Share This Page