Search Code
  Home arrow Search Code arrow search_v1.1
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
SEARCH CODE

search_v1.1
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2002-01-18

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    This is a modified version of The LLama's search script, which will query a MySQL Database and display the results. I modified by separating the script into two , and including not only the database connector, but instructions on getting the whole thing to work with little up front MySQL or PHP knowledge.

    By : MatriX

    #############################################
    #<-------- CUT HERE FOR README -------->#
    #############################################
    #//////////////////////////////////////
    #// MODIFIED 09 JUNE 01 - MatriX
    #// Version 1.1
    #//
    #// Thanks to LLama for the original script! <The LLama (scripts@projectgis.org)> #// I have made the following modifications the original PHP to make it easier for newbies (like myself)
    #// to get it working. The following has been modified:
    #//
    #// 1. Broke the original single posted script into two scripts - there was no "cut" to
    #// separate the two, no big deal, but this will save a few minutes for a newbie
    #// 2. Supplied generic database connector information. Hey, for PHP and MySQL newbies figuring
    #// out how to enter the dabase information in a script can be a real bitch!
    #// 3. Added a version number in case further modifications are made, 'cause this is a great script!
    #//
    #// -MatriX <matrix@digitalcyanide.net> #//
    #///////////////////////////////////////
    #############################################

    Ramblings:
    I came across this script at http://evilwalrus.com, a great source for PHP
    scripts. Besides, they have a really cool logo, so check them out. Being
    new at both MySQL and PHP, I was looking for a way to convert a flat text
    based database of over 25,000 rows of 12 fields to SQL, and save some CPU
    and response time. I decided on using SQL and PHP. This script worked almost
    "out o the box" compared to all of the others I tried, and after minor tweaking was
    able to query the database I created. The biggest challenge was writing the database
    connector, which was probably the most time consuming part of the whole thing, so
    I decided to put this fabulous script back out into the wild with some changes to make
    it easier for others to use, and include a bit of documentation for the beginner. If you are
    not a beginner, then you probably are not reading this.

    Requirements:
    MySQL
    PHP
    Database - no brainer
    Web Server - again, no brainer
    Suggested:
    Linux B}
    phpMyAdmin
    Roxen or Apache

    Usage:
    OK, here we go. First off, you need to know the following in order to use this script:

    Database Servers Name - The sever the database is located on
    Database Users Name - The user name used to connect to the database
    Database Users Password - The users password (sometimes NULL, but not a good idea)
    Database Name - The name of the database you are going to be acessing
    Database Table Name - The table inside the database you are going to query

    There are two files that I have named find.php, and results.php. I chose these names as they
    are intuitive. Find.php is the page that you will call in your browser (e.g. http://mydomain.net/find.php),
    and enter the information you want to search for. When you click the Submit Query button, your results
    will appear in the other script - results.php. See, I-N-T-U-I-T-I-V-E.

    I have placed the variables in the script, where originally this was left out. All you need to do is fill in
    the information and you are all set.

    where:

    The two place holders for your query are labeled as some_data_1, and some_data_2. These two
    expressions with the underline in between (_) are where you need to enter the table data field, without the
    underline is displayed in the browser exactly as you enter it, it is NOT part of the query, so you can change
    this to what you want the user to see.

    MODIFY find.php -
    In the find.php script, locate "name= " This is where you need to enter the field you are searching in
    for your data. You can and should have multiple fields, as in the example, and search for comparitive
    matches. Just enter each of the fields on their own line

    Some Data 1: <input type=text name=some_data_1 size=25 maxlength=25> Some Data 2: <input type=text name=some_data_2 size=25 maxlength=25> When you click on Submit Query, the data fields you entered will be queried to find a match for what you
    entered on the web page, find.php. The query will be run from results.php which takes the information you
    entered on find.php, searches the database, and displays the results. Here is where you need to enter
    your database connect information.

    MODIFY results.php
    $db_host = 'localhost'; - The Database Server
    $db_user = 'dbase_user'; - The Database Users Name
    $db_pass = 'dbase_user_password; - The Database Users Password
    $db_name = 'dbase_name'; - The Database name
    $db_table = 'dbase_table_name'; - The Database Table you are querying

    That should be it. Once you have finished entering your information, point your browser to find.php, enter
    something in the fields, click Submit Query, and watch the results. Unless I have missed something in the script,
    or you forgot to fill in some of the information correctly, you should have a working PHP-MySQP Database search
    page. At least it was working on my server when I wrote this and zipped it up!


    Lifeline:
    Sorry, you cannot use your host as a lifeline. I have tried to document as well as I can, how to get this puppy working
    for you, and as a matter of fact, I think the character count in this readme is larger than the actual scripts! If you still need
    help, you can try some of the following links for information or assistance. If you make further modifications, please let me
    know. Last but not least, thank The LLama (scripts@projectgis.org) for the original script.

    EvilWalrus.com
    php.net
    mysql.com


    End Transmission:
    -MatriX <matrix@digitalcyanide.net> ####################################################
    #<-------- CUT HERE - BELOW IS FIND.PHP -------->#
    ####################################################
    // Begin find.php

    <form method=post action="results.php"> Search For:
    <p> Some Data 1: <input type=text name=some_data_1 size=25 maxlength=25> <p> Some Data 2: <input type=text name=some_data_2 size=25 maxlength=25> <p> <input type=submit> </form> // End find.php

    #######################################################
    #<-------- CUT HERE - BELOW IS RESULTS.PHP -------->#
    #######################################################
    // Begin results.php

    <?
    //MatriX Connector MOD

    $db_host = 'dbase_server';
    $db_user = 'dbase_user';
    $db_pass = 'dbase_user_password';
    $db_name = 'dbase_name';
    $db_table = 'dbase_table_name';
    $conn = mysql_connect($db_host,$db_user,$db_pass);
    mysql_select_db($db_name,$conn);

    //MatriX connector MOD

    // ---- END CONFIGURATIONS ------------------------------------------//

    if ($some_data_1 == "")
    {$some_data_1 = '%';}

    if ($some_data_2 == "")
    {$some_data_2 = '%';}
    // $some_data_1 and $some_data_2 are the two column names I used. Change this to fit your database
    $result = mysql_query ("SELECT * FROM dbase_name
    WHERE some_data_1 LIKE '%$some_data_1%'
    AND some_data_2 LIKE '%$some_data_2%'
    ",$conn);

    if ($row = mysql_fetch_array($result)) {

    do {
    PRINT "Our database contains the following records: <br><br>";
    PRINT "<b>Some Data 1: </b> ";
    print $row["some_data_1"];
    print (" ");
    print ("<br>");
    PRINT "<b>Some Data 2: </b> ";
    print $row["some_data_2"];
    print ("<p>");
    print ("<p>");
    } while($row = mysql_fetch_array($result));
    } else {print "Sorry, no records were found!";}

    ?> // End results.php

    // END OF FIND_V1.1
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Search Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Improve your build process with IBM Rational Build Forge, Part 2: Automate builds for a real-world Tomcat project

    Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Tester for SOA Quality V7.0.1

    Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services.
    FREE! Go There Now!


    NEW! Develop Systems Software Assets with IBM Rational Asset Manager

    Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager.
    FREE! Go There Now!


    NEW! Download DB2 Express-C 9.5

    Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages.
    FREE! Go There Now!


    NEW! Webcast: Application security testing and Web compliance

    Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for People

    Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity.
    FREE! Go There Now!


    NEW! Trial download: IBM Informix Dynamic Server Express Edition V11.0

    Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    Role of Integrated Requirements Management in Software Delivery

    As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change.
    FREE! Go There Now!


    Check out the new Jazz space on developerWorks

    <a href="http://zeus.developershed.com/shonuff.php?blackbird=3853&zoneid=442&source=&dest=http%3A%2F%2Fwww.ibm.com%2Fdeveloperworks%2Fspaces%2Fjazz%3FS_TACT%3D105AGY31%26S_CMP%3DDEVSHED&ismap="><img src="http://images.devshed.com/corp/img/news/jazz01.gif" alt="developerWorks Jazz space" align="left"></a>You've heard the buzz about Jazz... want to know more about it from a developer's perspective? Check out the Jazz space on developerWorks. This space is an up-to-date resource for developers, including technical information about Jazz and products built on Jazz, like Rational Team Concert Express. The Jazz space includes content from a wide variety of sources, including links, feeds, and comments from experts.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    SEARCH CODE ARTICLES

    - PHP IP Blocking
    - Search engine with ranking feature
    - Ajax access to Google API
    - Table Searcher
    - Search_It
    - FTP SEARCH
    - Search and Replace class
    - Simple Search on mysql database
    - Search Your Database
    - search_v1.1
    - Database Searching Class





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT