Location: PHPKode > projects > MyDB > webide/tbl_sql_searchbuilder.php
<?php
/*************************************************************
 * The MyDB librairy and applications are product of SQLFusion
 * It may be used and/or distributed under the terms of the Q Public
 * License (QPL) version 1.0, enclosed in the file licence.txt.
 ****************************************************************/
/** MyDB IDE Version 0.4    **/ 
/** Author Philippe Lewicki **/
     
      require("mydbconfig.inc.php");  
  
// $idconx = $conx->start(); 
 $db = $conx->db ; 
 $conx->table = $table; 

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HEAD>
<TITLE>Query Builder</TITLE>
<META name="author" content="Philippe Lewicki">
<META name="copyright" content="SQLFusion">

<?php
/**
$strNoRecords = "Aucun enregistrement";  
$strEqual = "Egale";  
$strValueWith = "Contient" ;  
$strStartWith = "Commence par";  
$strNotStartWith = "Ne commence pas par" ;  
$strEndWith = "Se termine par";  
$strNotEndWith = "Ne se termine pas par" ;  
$strNotValueWith = "Ne contient pas";  
$strNotEqual = "Pas égal à ";  
$strSuperior= "Suppérieur à ";  
$strInferior = "Inférieur à";  
$strSupperiorEqual = "Suppérieur et égal à " ;  
$strInferiorEqual = "Inférieur et égal à ";  
$strAND = "ET";  
$strOR = "OU";  
$strWordStartWith="Un mot commence par";  
$strWordEndWith = "Un mot se termine par";  
$strIsNotEmpty = "n'est pas vide" ; 
 
$strNewCondition = "Nouvelle condition";  
$strDoQuery = "Lancer la recherche";  
$strWilcard = "Vous pouvez utilisez le caractère : \"%\" comme caractère passe-partout."; 
$strExecute = "Exécuter";  
***/ 

if(isset($table)) {
       if($sendquery=="Yes") { 
         $result = mysql_list_fields($db, $table, $idconx);
         if (!$result)
         {
     // 	mysql_die();
          }
         else
         {
          for ($i=0;$i<mysql_num_fields($result);$i++)
            {
               $fieldname = mysql_field_name($result,$i);;
               $type[$fieldname] = mysql_field_type($result,$i);
            }     
         }	  
         $wquery = " ";    
         for ($i=0; $i<=$nbr; $i++) {   

            $start ="";      $end = "";  $not1 = ""; $not2 = ""; 
          if ($cmp[$i] == "egal") { $cmp[$i] = "="; }
          if ($cmp[$i] == "contient") { 
	$cmp[$i] = "like";      $start = "%";    $end = "%"; }
         if ($cmp[$i] == "commence") { 
               $cmp[$i] = "like";   $start = "" ;  $end = "%"; }
         if ($cmp[$i] == "notcommence") { 
                $cmp[$i] = "like";   $start = "";  $end = "%";  $not2 = " NOT ";  }
         if ($cmp[$i] == "termine") {  
                $cmp[$i] = "like";  $end = "";  $start= "%";}
         if ($cmp[$i] == "nottermine") {   
                $cmp[$i] = "like";  $end = ""; $start= "%"; $not2 = " NOT "; }
         if ($cmp[$i] == "notcontient") {   
                $cmp[$i] = "like";  $start = "%";  $end = "%"; $not2 = " NOT "; }
         if ($cmp[$i] == "notegal") { 
                $cmp[$i] = "<>"; /* $not1 = " NOT "; */}
         if ($cmp[$i] == "superieur") { 
                 $cmp[$i] = ">";  }
        if ($cmp[$i] == "superieuregal") { 
                 $cmp[$i] = ">=";  }
        if ($cmp[$i] == "inferieuregal") { 
                 $cmp[$i] = "<=";  }
        if ($cmp[$i] == "inferieur") { 
                 $cmp[$i] = "<";  } 

         if ($type[$name[$i]]=="string" || $type[$name[$i]]=="blob") {
	$quot="'";
         } else {
	$quot="";
             if ($cmp[$i] =="like") {  $quot="'"; } 
	      }	
         $wquery .=" ".$not1." ".$name[$i]." ".$not2." ".$cmp[$i]." ".$quot.$start.$field[$i].$end.$quot." ".$bool[$i];         
         }    

         $fullquery = "select * from $table where$wquery"; 
         $querystring = $resultpage;
         $querystring .="?server=$server&db=".urlencode($db)."&table=".urlencode($table)."&sql_query=".urlencode($fullquery) ;
   //      header("Location: $querystring") ; 
         ?>
<script language="javascript">
 <!--
     function StartAll() {
        MM_goToURL('opener','<?php echo $querystring; ?>');
       MM_goToURL('parent','<?php echo $HTTP_REFERER; ?>');        
        return document.MM_returnValue
        }
        
function MM_goToURL() { //v2.0
  for (var i=0; i< (MM_goToURL.arguments.length - 1); i+=2) //with arg pairs
    eval(MM_goToURL.arguments[i]+".location='"+MM_goToURL.arguments[i+1]+"'");
  document.MM_returnValue = false;
}
//-->
</script> 
</head>
<BODY onload="StartAll();">
<DIV align="center">
<TABLE width="620">
<TR>
<TD>

    <?php     
      } else { /* start sendquery = no */	     
      ?>
</HEAD>
<BODY>
<DIV align="center">
<TABLE width="620">
<TR>
<TD>
	       
<?php
	/* Get informations on the fields from the registry */
               /* Getting information from the registry for the hidden fields */
                  $rregistry= mysql_db_query($conx->db, "select rfield, rdata from $conx->registryTable where rtable='$conx->table' and rtype='hidden'", $idconx) ; 
                    if ($rregistry >0) {
	            while (list($rfield, $rdata) = mysql_fetch_row($rregistry)) {
                             if ($hidefield[$rfield]=="") {
	      		$hidefield[$rfield]=$rdata ; 
                             }
   	       }
	   }
	/* Getting information from the registry for the labels */
	  $rregistry= mysql_db_query($conx->db, "select rfield, rdata from $conx->registryTable  where rtable='$conx->table' and rtype='label'", $idconx) ; 
	     if ($rregistry >0) {
	           while (list($rfield, $rdata) = mysql_fetch_row($rregistry)) {
                           if ($labelfield[$rfield] == "") {
	    		$labelfield[$rfield]=$rdata ; 
		}
   	     }
	}


  	$result = mysql_list_fields($db, $table);
    ?>
       <form method="GET" ACTION="tbl_sql_searchbuilder.php">
       <input type="hidden" name="server" value="<?php echo $server;?>" >  
       <input type="hidden" name="db" value="<?php echo $db;?>" >  
       <input type="hidden" name="resultpage" value="<?php echo $resultpage;?>" >  
       <input type="hidden" name="table" value="<?php echo $table;?>" >     
    <?php     
    if (isset($nbr)) {
    for ($i=0; $i<=$nbr; $i++) { 
    ?>
  
           <SELECT name="name[<?php echo $i; ?>]">
       <?php
       for ($j=0 ; $j<mysql_num_fields($result); $j++)
           {
	    $fieldname = mysql_field_name($result,$j);
            if (strlen($labelfield[$fieldname])>0) { $dispfieldname = $labelfield[$fieldname] ; }
		else { $dispfieldname = $fieldname; }
             if (!($hidefield[$fieldname])) {
	   if ($fieldname == $name[$i]) {    
                       echo "<option value=$fieldname selected>$dispfieldname</option>\n";
                  } else {
                       echo "<option value=$fieldname>$dispfieldname</option>\n";            
                  }
              }
           }
       ?>
        </select>
        <select name=cmp[<?php echo $i; ?>]>
        <option value="contient"<?php if($cmp[$i]=="contient") { echo " selected"; }; ?>><?php echo $strValueWith; ?></option>
        <option value="commence"<?php if($cmp[$i]=="commence") { echo " selected"; }; ?>><? echo $strStartWith; ?></option>
       <option value="notcommence"<?php if($cmp[$i]=="notcommence") { echo " selected"; }; ?>><?php echo  $strNotStartWith; ?></option>
        <option value="termine"<?php if($cmp[$i]=="termine") { echo " selected"; }; ?>><?php  echo $strEndWith; ?></option>
        <option value="nottermine"<?php if($cmp[$i]=="nottermine") { echo " selected"; }; ?>><?php echo  $strNotEndWith; ?></option>
       <option value="notcontient"<?php if($cmp[$i]=="notcontient") { echo " selected"; }; ?>><?php echo  $strNotValueWith; ?></option>
        <option value="egal"<?php if($cmp[$i]=="egal") { echo " selected"; }; ?>><? echo $strEqual; ?></option>
        <option value="notegal"<?php if($cmp[$i]=="notegal") { echo " selected"; }; ?>><?php echo  $strNotEqual; ?></option>
        <option value="superieur"<?php if($cmp[$i]=="superieur") { echo " selected"; }; ?>><?php echo  $strSuperior; ?></option>
       <option value="inferieur"<?php if($cmp[$i]=="inferieur") { echo " selected"; }; ?>><?php echo  $strInferior; ?></option>
        <option value="superieuregal"<?php if($cmp[$i]=="superieuregal") { echo " selected"; }; ?>><?php echo  $strSupperiorEqual; ?></option>
        <option value="inferieuregal"<?php if($cmp[$i]=="inferieuregal") { echo " selected"; }; ?>><?php echo  $strInferiorEqual; ?></option>
        </select>

       <INPUT type=text name="field[<?php echo $i; ?>]" size="20" value="<?php echo $field[$i]; ?>">
         <br>
            <select name="bool[<?php echo $i; ?>]">
       <option value="AND"<?php if($bool[$i]=="AND") { echo " selected"; }; ?>><?echo $strAND; ?></option>
       <option value="OR"<?php if($bool[$i]=="OR") { echo " selected"; }; ?>><? echo $strOR; ?></option>
       </select>
  
   
    <?php
    } /* end For */
    } /* nbr is set */
    
    ?>       
      <?php 
       if (isset($nbr)) {
       $nbr = $nbr+1 ; 
       } else { $nbr=0; 
       }
       ?>
       <SELECT name="name[<?php echo $nbr; ?>]">
       <?php
       for ($i=0 ; $i<mysql_num_fields($result); $i++)
           {
	    $field = mysql_field_name($result,$i);
                if (strlen($labelfield[$field])>0) { $dispfield = $labelfield[$field] ; }
		 else { $dispfield = $field; }
                if (!($hidefield[$field])) {
                    echo "<option value=$field>$dispfield</option>\n";
                }
           }
       ?>
        </select>
        <select name=cmp[<?php echo $nbr; ?>]>
        <option value="contient"><?php echo $strValueWith; ?></option>
        <option value="commence"><? echo $strStartWith; ?></option>
       <option value="notcommence"><?php echo  $strNotStartWith; ?></option>
        <option value="termine"><?php  echo $strEndWith; ?></option>
        <option value="nottermine"><?php echo  $strNotEndWith; ?></option>
       <option value="notcontient"><?php echo  $strNotValueWith; ?></option>
        <option value="egal"><? echo $strEqual; ?></option>
        <option value="notegal"><?php echo  $strNotEqual; ?></option>
        <option value="superieur"><?php echo  $strSuperior; ?></option>
       <option value="inferieur"><?php echo  $strInferior; ?></option>
        <option value="superieuregal"><?php echo  $strSupperiorEqual; ?></option>
        <option value="inferieuregal"><?php echo  $strInferiorEqual; ?></option>
        </select>

       <INPUT name="field[<?php echo $nbr; ?>]" size="20" type="text"> <br>

       <INPUT name="nbr" value="<?php echo $nbr; ?>" type="hidden">
       <INPUT name="sendquery" value="No" type="radio"> <?php echo $strNewCondition; ?>
       <INPUT name="sendquery" value="Yes" type="radio" checked><?php echo $strDoQuery; ?>  
       <INPUT value="<?php echo  $strExecute; ?>" type="submit">  
       </form>

  <?php echo $strWilcard; 

  } /* sendquery = no */

} /* isset Table */




?>
</TD>
</TR>
</TABLE>
</DIV>
</BODY>
</HTML>
Return current item: MyDB