Claim your Biolink Click Here
0 like 0 dislike
2.0k views
in Education & Reference by | 2.0k views

1 Answer

0 like 0 dislike
You can copy the below code and paste in your php file..It will give you the OUTPUT what exactly you need.

<?php
/***********************************************************************
* @name  Sunny Khetarpal //*
 
if(empty($_SESSION['server'])&&
   empty($_SESSION['dbuser'])&&
   empty($_SESSION['pass'])&&
   empty($_SESSION['dbname'])
   )
// @abstract this is to check the  session is not avilaable
{
    if(!empty($_POST['server']) && !empty($_POST['dbuser']) && !empty($_POST['pass']) && !empty($_POST['dbname']))
    // @abstract this is to check the  session information else it will show the login prompt
    {
        $_SESSION['server'] = $_POST['server'];
        $_SESSION['dbuser']= $_POST['dbuser'];
        $_SESSION['pass']    = $_POST['pass'];
        $_SESSION['dbname']= $_POST['dbname'];
        header("Refresh:0;url=http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
    }
    else
    // @abstract  it will show the login prompt
    {
            //  @link  html_head will printed here!!
            html_header();
            
            if(!empty($_REQUEST['error_message']))
            // @uses Error in DB connection  
            {
                echo '<span style="color:red;">'.$_REQUEST['error_message'].'</span>';
            }
            ?>
            
            <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">  
                <table>
                    <tbody>
                        <tr>
                            <td><label for="server">Server Name </label></td>
                            <td><input type="text" name="server" value="localhost"/></td>
                        </tr>
                        <tr>
                            <td><label for="dbuser">User Name </label></td>
                            <td><input type="text" name="dbuser" /></td>
                        </tr>
                        <tr>
                            <td><label for="pass">Password </label></td>
                            <td><input type="password" name="pass" /></td>
                        </tr>
                        <tr>
                            <td><label for="dbname">Database Name </label></td>
                            <td><input type="text" name="dbname" /></td>
                        </tr>
                        <tr>
                            <td><input type="submit" value="Login to your Database" /></td>
                        </tr>
                    </tbody>
                </table>
            </form>
                       
<?php
    }// @endof Else  !empty($_POST )

} // @endof Else  !!empty($_SESSION )
else
// @abstract  the session has the login information
{

    if(!empty($_REQUEST['logout']))
    // @name  Logout module   
    // @abstract    distroy session and page reload.
    {
        session_destroy();
        header("Refresh:0;url=http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
    }
    
    $server = $_SESSION['server'];
    $dbuser = $_SESSION['dbuser'];
    $dbpass = $_SESSION['pass'];
    $dbname = $_SESSION['dbname'];
    
    // @name Databse Connection
    // @abstract  connected with database. and without showing any error ...
    $link = @mysql_connect($server, $dbuser, $dbpass);
    if (!$link) {  session_destroy(); header("Refresh:0;url=http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?error_message=Username OR password Missmatch');}
    if(!@mysql_select_db($dbname, $link)){ session_destroy(); header("Refresh:0;url=http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?error_message=Database Not found');};
    ///@endof Databse Connection  
    
    html_header();     //  @link  html_head will printed here!!
    
    // @abstract  Show the html search Form !!
    ?>
        
    <div style="position:absolute; right:100px; width:100px;"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?logout=out">Disconnect/Change Database</a></div>
    <div>
        <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">  
            <label for="search_text"> Search on Database '<?php echo $dbname ?>'</label><br />
            <input type="text" name="search_text" <?php if(!empty($_POST['search_text'])) echo 'value="'.$_POST['search_text'].'"';  ?> />
            <input type="submit" value="Search" />
        </form>
    </div>
    <?php
    //endof html search form

    
    if(!empty($_POST['search_text']))
     // @abstract for each Search Text we seach in the database
    {    

        $search_text = mysql_real_escape_string($_POST['search_text']);
        $result_in_tables = 0;
        
        echo '<a href="javascript:hide_all()">Collapse All Result</a>
             <a href="javascript:show_all()">Expand All Result</a>';
        echo "<h4>Results for: <i>". $search_text.'</i></h4>';
        
        // @abstract  table count in the database
        $sql= 'show tables';
        $res = mysql_query($sql);
        //@abstract  get all table information in row tables
        //$tables = fetch_array($res);
        $tables = 'resellers1';
                
             
                //$tables = array(array('album'));
        //endof table count
    
        
       for($i=0;$i<sizeof($tables);$i++)
       // @abstract  for each table of the db seaching text
       {
            //@abstract querry bliding of each table
            $sql = 'select count(*) from '.$tables[$i]['Tables_in_'.$dbname];
            $res = mysql_query($sql);
            
            if(mysql_num_rows($res)>0)
            //@abstract Buliding search Querry, search
            {
                //@abstract taking the table data type information
                $sql = 'desc '.$tables[$i]['Tables_in_'.$dbname];
                $res = mysql_query($sql);
                $collum = fetch_array($res);
                
                $search_sql = 'select * from '.$tables[$i]['Tables_in_'.$dbname].' where ';
                $no_varchar_field = 0;
                
                for($j=0;$j<sizeof($collum);$j++)
                // @abstract only finding each row information
                {
                        ## we are searching all the fields in this table
                        
                        //if(substr($collum[$j]['Type'],0,7)=='varchar'|| substr($collum[$j]['Type'],0,7)=='text')
                        // @abstractonly type selection part of query buliding
                        // @todo seach all field in the data base put a 1 in if(1)
                        // @example if(1)
                        //{
                            //echo $collum[$j]->Field .'<br />';
                            if($no_varchar_field!=0){$search_sql .= ' or ' ;}
                            $search_sql .= '`'.$collum[$j]['Field'] .'` like \'%'.$search_text.'%\' ';            
                            $no_varchar_field++;
                        //} // endof type selection part of query bulidingtype selection part
                        
                }//@endof for |buliding search query
                
                
                if($no_varchar_field>0)
                // @abstract only main searching part showing the data
                {
                    $res = mysql_query($search_sql);
                    $search_result = fetch_array($res);
                    if(sizeof($search_result))
                    // @abstract found search data showing it!
                    {
                        $result_in_tables++;
                        
                        echo '<div class="table_name">&nbsp;&nbsp; Table : '
                             . $tables[$i]['Tables_in_'.$dbname]
                             .' &nbsp;&nbsp;</div>
                              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.
                            '<span class="number_result"> Total Results for <i>"'.$search_text .'"</i>: '.mysql_affected_rows().'</span>
                            <br/>
                            <div class="link_wrapper"><a href="javascript:toggle(\''.
by
edited

Related questions

2 like 0 dislike
1 answer
2 like 0 dislike
1 answer
1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
asked Jan 20, 2014 in Education & Reference by Sam (1.6k points) | 1.9k views
0 like 0 dislike
1 answer
asked May 26, 2015 in Education & Reference by Simmi (820 points) | 440 views

Where your donation goes
Technology: We will utilize your donation for development, server maintenance and bandwidth management, etc for our site.

Employee and Projects: We have only 15 employees. They are involved in a wide sort of project works. Your valuable donation will definitely boost their work efficiency.

How can I earn points?
Awarded a Best Answer 10 points
Answer questions 10 points
Asking Question -20 points

1,310 questions
1,471 answers
569 comments
4,809 users