Login   Register  
PHP Classes
elePHPant
Icontem

File: try3.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Craig Heydenburg  >  better_field_search  >  try3.php  >  Download  
File: try3.php
Role: Example script
Content type: text/plain
Description: advanced example
Class: better_field_search
Generalized, flexible class to search a mysql DB
Author: By
Last change:
Date: 12 years ago
Size: 2,775 bytes
 

Contents

Class file image Download
<?
// this is a slightly more advanced example of how to use this class.
// it demonstrates how you can format your output yourself.

/*
This is a sample of how to implement the class.search.php class.
The class was originally written by
Sujith Nair [sujith_77@hotmail.com]
On September 12, 2001

greatly modified and enhanced by
Craig Heydenburg [craigh@mac.com]
May 19, 2002
*/
require ("class.search.php");


// Change the information below to reflect your needs
$try=new search_fields("hostname","username","password","dbname");
$table="tablename";
$cols=array("col1_name","col2_name");
// end

$css="<STYLE TYPE='text/css'>
    BODY {
        background-color: white;
        font-family:Arial, Helvetica, Sans-Serif;
    }
    TABLE.sl { /* this is a 'small-list' table */
        font-size: 9px;
        font-family: Arial;
        background-color: #eeeeee;
        border: 1px solid Black;
        width:100%;
    }
    TR.hl { /* this is a table headline */
        background-color: #666666;
        color: white;
        text-align: center;
    }
    TR.slr { /* this is a table row */
        background-color: white;
        text-align: center;
    }
    TR.slr_alt { /* this is an alternate table row */
        background-color: transparent;
        text-align: center;
    }
</STYLE>"
;
if (
$submit<>"search") {
?>
<HTML>
<HEAD>
<TITLE>Search</TITLE>
<? echo $css ?>
</HEAD>
<BODY>
<B>Search</B><BR>
<form action="<? echo basename($PHP_SELF?>" method="post">
    <BR>
Enter search terms: <INPUT TYPE="TEXT" NAME="terms">
<INPUT TYPE="hidden" Name="submit" value="search">
<button type="submit" name="sub_button">Search</button></FORM>
</BODY>
</HTML>

<?
} else {
?>
<HTML><HEAD><TITLE>Search Results</TITLE>
<? echo $css ?>
</HEAD>
<BODY>
<?
function alt_row($tr_class) {
    
// alternate row colors by alternating CSS classes
    
if ($tr_class=="slr") {
        
$tr_class="slr_alt";
    } else {
        
$tr_class="slr";
    }
    return 
$tr_class;
}
$try->make_str($table,$terms,$cols);
$result=$try->getresult();
// Match the keywords and display the result
print ("Keywords used: ".$try->keywords()."<BR><BR>\n");
print (
"Total ".$try->num_rows." results found"."<br><br>\n");
print (
"<TABLE class='sl' style='width:auto;'>\n");
// print column names
print ("<TR class='hl' style='text-align:left;'>\n");
while (list(
$k,$v)=each($try->col_names())) {
    print (
"<TD>$v</TD>\n");
}
print (
"</TR>\n");
// print data
$tr_class="slr";
while (list(
$k,$v)=each($result)) {
    print (
"<TR class='$tr_class' style='text-align:left;'>\n");
    while (list(
$k2,$v2)=each($v)) { 
        print (
"<TD>$v2</TD>\n");
    }
    print (
"</TR>\n");
    
$tr_class=alt_row($tr_class); // alternates row color
}
print (
"</TABLE>\n");
?>
<BR><BR><A HREF="<? echo basename($PHP_SELF?>">Search Again</A>
</BODY>
</HTML>
<?
}
?>