www.webdeveloper.com
Page 3 of 3 FirstFirst 123
Results 31 to 36 of 36

Thread: search string in mysql

  1. #31
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    Let's just take a (very) basic example, and see if you can figure out how/where to use it in your application:
    PHP Code:
    $result mysql_query($sql);
    if(
    mysql_num_rows($result) > 0) {
      
    // do the stuff you want to do when results are found here
    }
    else {
      
    // no results were found, so handle that situation here, for example:
      
    echo "<p>Sorry, no results matched your search.</p>";

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  2. #32
    Join Date
    Oct 2013
    Posts
    28
    hmmm, I have been trying all type of options (I think) but could not find the right one to use. The best one I can come up with is:

    PHP Code:
      # create a MySQL REGEXP for the search: 
      
    $regexp "REGEXP '[[:<:]]($search)[[:>:]]'"
      
    $query "SELECT * FROM `galleries` WHERE UPPER(`keywords1`) $regexp OR "
               
    "`keywords2` $regexp"
      
    $result mysql_query($sql);
      
    echo 
    "<table>\n"
    if(
    mysql_num_rows($result) > 0


        echo 
    "<tr>"
        echo 
    "<td><img src=../thumbs/{$row['type']}/{$row['folder']}/{$row['date']}-{$row['num']}/{$row['thumbimage']} border=1></td>";
        echo 
    "<td>{$row['name']}</td>"
        echo 
    "<td>{$row['date']}</td>"
        echo 
    "<td><a href=../members/viewgallery.php?id={$row['id']} target=blank>View</a></td>"
        echo 
    "</tr>\n"
      }  


    else {
      echo 
    "<p>Sorry, no results matched your search.</p>";

    But I really dont know how to do this :/ Can you please show me?

  3. #33
    Join Date
    Oct 2013
    Posts
    28
    Sombody that are able to help me?

  4. #34
    Join Date
    Oct 2013
    Posts
    28
    I really need a hint. Can some one please help me with this part?

  5. #35
    Join Date
    Oct 2013
    Posts
    28
    Sombody that know where I can find the answer for this?

  6. #36
    Join Date
    Oct 2013
    Posts
    28
    I found out my self. Here is the code if some one else should ever need it:
    PHP Code:
    <?php 
    if(isset($_POST['search'])) 

      
    $connx mysql_connect('localhost''cms_main'',J4(tgM2X.(~') or die("connx"); 
      
    $db mysql_select_db('cms_main') or die(mysql_error()); 
      
      
    # convert to upper case, trim it, and replace spaces with "|": 
      
    $search = (ini_get('magic_quotes_gpc')) ? stripslashes($_POST['search']) : 
                
    $_POST['search']; 
      
    $search mysql_real_escape_string($search); 
      
    $search strtoupper(preg_replace('/\s+/''|'trim($_POST['search']))); 
      
      
    # create a MySQL REGEXP for the search: 
      
    $regexp "REGEXP '[[:<:]]($search)[[:>:]]'"
      
    $query "SELECT * FROM `galleries` WHERE UPPER(`keywords57`) $regexp OR "
               
    "`keywords58` $regexp OR "
               
    "`keywords59` $regexp OR "
               
    "`keywords60` $regexp"
      
    $result mysql_query($query) or die($query " - " mysql_error()); 

          
    echo 
    "<table>\n"
    while(
    $row mysql_fetch_assoc($result)) 


        echo 
    "<tr>"
        echo 
    "<td><img src=../thumbs/{$row['type']}/{$row['folder']}/{$row['date']}-{$row['num']}/{$row['thumbimage']} border=1></td>";
        echo 
    "<td>{$row['name']}</td>"
        echo 
    "<td>{$row['date']}</td>"
        echo 
    "<td><a href=../members/viewgallery.php?id={$row['id']} target=blank>View Photoset</a></td>"
        echo 
    "</tr>\n"
      }  

     else {
      echo 
    "<p>Sorry, no results matched your search.</p>";
    }
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles