Help With PHP Search

Discussion in 'PHP' started by GeelongTECH, Jan 3, 2011.

  1. #1
    Hello,
    I have a script that writes to database "video" & table "videos".

    In "videos" i have a field called "tags" witch has a example value of "hd, test, 1080p"
    below is an like to image shack to view a screen shot of my database
    http://img543.imageshack.us/img543/2808/mysqls.jpg

    I want a file called search.php witch will access my database and try and match the search keywords with the tags in the field "tags"

    Please Help
    Chris
     
    GeelongTECH, Jan 3, 2011 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    SELECT * FROM `table` WHERE `fieldyouwanttosearching` LIKE '%keyword%'

    Please read the MySQL documentation, this is just to easy...
     
    EricBruggema, Jan 3, 2011 IP
  3. GeelongTECH

    GeelongTECH Peon

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''videos' WHERE 'tags' LIKE 'written'' at line 1
     
    GeelongTECH, Jan 3, 2011 IP
  4. GeelongTECH

    GeelongTECH Peon

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I will admit i know very little about MySQL.

    The code i'm using is
    
    <?php
    $query9="SELECT * FROM 'videos' WHERE 'tags' LIKE '".$_GET['k']."'";  // query string stored in a variable
    $rt9=mysql_query($query9);          // query executed 
    echo mysql_error();                    // if any error is there that will be printed to the screen 
    while($nt9=mysql_fetch_array($rt9)){
    echo '<div id="'.$nt9['id'].'"  class="box ">
    <div class="box_image">
    <a href="/watch?v='.$nt9['id'].'" rel="bookmark">
    <img src="/images/play.png" id="overlayimg" style="background-image: url('.$nt9['small_img_url'].');" alt="" title="'.$nt9['name'].'"/>
    </a>
    </div>
    <div class="box_detail">
    <h3><a  href="/watch?v='.$nt9['id'].'" rel="bookmark">'.$nt9['name'].'</a></h3>
    <div class="ratings"><div style="margin-bottom: 5px;"><img src="/images/starOff.png" style="border: 0px none;"><img src="/images/starOff.png" style="border: 0px none;"><img src="/images/starOff.png" style="border: 0px none;"><img src="/images/starOff.png" style="border: 0px none;"><img src="/images/starOff.png" style="border: 0px none;"></div></div>
    <div class="box_description" style="line-height: normal; display: none; text-align: left;">
    <small class="super_light">'.$nt9['upload_date'].'</small>
    <div style=\'margin-top: 5px; line-height: normal;\'><p>'.$nt9['description'].'</p>
    </div>
    <div class="smaller light_blue" style="margin-top: 5px;">
    <a href="/category/?cat='.$nt9['category'].'" rel="category">'.$nt9['category'].'</a>
    </div>
    </div>
    </div>
    </div>';
    ?>
    
    PHP:
    if you goto search.php?k=hd i want it to echo the "id", "name", category" and "small_img_url"
     
    Last edited: Jan 3, 2011
    GeelongTECH, Jan 3, 2011 IP
  5. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #5
    use full text search and its much much faster than select query. sometimes select query using LIKE may give weird results.
     
    olddocks, Jan 3, 2011 IP
  6. tprinty

    tprinty Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You need some wild cards in your search query
    $query9="SELECT * FROM 'videos' WHERE 'tags' LIKE '%".$_GET['k']."%'"; // query string stored in a variable

    the % is the wild card symbol
     
    tprinty, Jan 3, 2011 IP
  7. Moustafa.Elkady

    Moustafa.Elkady Member

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #7
    Moustafa.Elkady, Jan 3, 2011 IP