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! "ebook: Exploring IBM SOA Technology & Practice

    Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success.
    FREE! Go There Now!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo.
    FREE! Go There Now!


    NEW! Download a free trial of WebSphere Business Modeler Advanced V6.1.1

    Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Software Analyzer V7.0

    Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle.
    FREE! Go There Now!


    NEW! IBM Rational Systems Development e-Kit

    As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br />
    FREE! Go There Now!


    NEW! Rational Talks to You: Manage RUP-based CMMI initiatives

    Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered!
    FREE! Go There Now!


    NEW! Rational Testing eKits

    Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing.
    FREE! Go There Now!


    NEW! Run your first CICS application on a PC using TXSeries for Windows

    Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1.
    FREE! Go There Now!


    NEW! Webcast: Accelerating Software Innovation with System z

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    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
    For more Enterprise Application Development news, visit eWeek