<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
  <title>Browse How-To Database</title>
  <LINK REL="stylesheet" HREF="/PHP/style.css">
  <META NAME="author"      CONTENT="Denice Deatrich">
  <META NAME="description" CONTENT="PHP web-based MySQL DB Management">
  <META NAME="keywords"    CONTENT="PHP web MySQL database">
</head>

<body>
  <h1>How-To Database</h1>
<?php
  
global $PHP_SELF;

  require(
"db_connect.php" );

  
checkDBStatus( );
  if(
is_array($HTTP_POST_VARS) ) { // then sort or search argument(s).
    
$i = 0;
    while( list(
$key, $val) = each($HTTP_POST_VARS) ) {
      
// process each POST variable argument
      
if( $key == "sort" ) {
        
$sortkey = $val;
        
//break;
      
}
      if(
$key == "search" && strlen($val) > 0 ) {
        
$searchkey = $val;
      }
      
$i++;
      
//echo "DBG: key:val is " . $key.":".$val . "<BR>";
    
}
  }
  if( (
$link=mysql_pconnect($DB_HOST, $DB_USER, $DB_PW)) ) {
    
$q = "select * from how_to"; // start to build query string
    
if( strlen($searchkey) > 0 ) {
      
// then add a search clause
      
$q = $q . " where " .$searchColumn. " like \"%" . $searchkey ."%\"";
    }
    if(
strlen($sortkey) > 0 ) {
      
// then add the required sort specification
      
$q = $q . " order by " . $sortkey;
    }

    
// now build the HTML forms
    
echo "
    <!-- This form is the header row with embedded sort buttons     -->
    <form action=\"$PHP_SELF\" method=\"post\">
      <font size=-1>Search: <font size=-1>
      <input type=\"input\" size=30 name=\"search\""
;
      if(
strlen($searchkey) > 0 ) {
        echo
" value=\"$searchkey\" ";
      }
      echo
"></font><select name=\"searchColumn\">
      <option value=\"keywords\">in Keywords
      <option value=\"topic\">in Topic
      <option value=\"os\">in OS
      </select></font>
      <table border=1 cols=6>
      <tr bgcolor=\"#e1ffd8\">
      <th width=30>#</th>
      <th width=180><input type=\"submit\" name=\"sort\" value=\"topic\"></th>
      <th width=50><input type=\"submit\" name=\"sort\" value=\"os\"></th>
      <th width=40><input type=\"submit\" name=\"sort\" value=\"ver\"></th>
      <th width=50><input type=\"submit\" name=\"sort\" value=\"arch\"></th>
      <th width=180>Keywords</th>
      </tr>
      </table>\n"
;
    if(
strlen($sortkey) > 0 ) {
      echo
"<input type=\"hidden\" name=\"sort\" value=\"$sortkey\">\n";
    }
    echo
"
    </form>"
;

    
/** okay, do the query. **/
    
$n = 0;
    if(
$res=mysql_db_query($DB_NAME, $q, $link) ) {
      
$nrows = mysql_num_rows($res);
      
/** fetch rows into array; we will display them in the 2nd form **/
      
while( ($row=mysql_fetch_array($res, MYSQL_NUM)) ) {
        
$arr[$n] = $row;
        
$n++;
      }
      
// for($i = 0; $i < $n; $i++) {echo $i. ": " .$arr[$i][0]. "\n<BR>";}
      
mysql_free_result( $res );
    }
    else {
      
printError( "QUERY", $link );
      exit;
    }
  }
  else {
    echo
mysql_errno().": ".mysql_error()."<BR>";
    exit;
  }
  echo
"
  <!-- This form contains the rows of data, each with a 'go' button -->
  <!-- The 'go' button is used to work on a single individual row   -->
  <form target=\"_blank\"
   action=\"/PHP/db/db_process_row.php?$rowid\" method=\"post\">
  <table border=1 cols=6>"
;
  
// data rows follow
  
if( $n <= 0 ) {
    echo
"<em><font color=\"red\">No more rows or no qualifying rows
    </font></em><br><br>"
;
  }
  else {
    for(
$i = 0; $i < $n; $i++ ) {
      
$rowid = $arr[$i][0];
      echo
"
      <tr><td width=30 align=\"right\" nowrap bgcolor=\"OldLace\">
      <font size=-1>"
. ($i+1) . "</font></td>
      <td width=180 nowrap bgcolor=\"AliceBlue\"><font size=-1>
      <A target=\"_blank\" HREF=\"db_process_row.php?$rowid\">"
      
. $arr[$i][1] . "</A></font></td>\n";
      echo
"<td width=50 nowrap bgcolor=\"lavender\"><font size=-1>"
       
. $arr[$i][2] . "</font></td>\n";
      echo
"<td width=40 bgcolor=\"MintCream\"><font size=-1>" . $arr[$i][3]
       .
"</font></td>\n";
      echo
"<td width=50 bgcolor=\"MistyRose\"><font size=-1>" . $arr[$i][4]
       .
"</font></td>\n";
      echo
"<td width=180 nowrap bgcolor=\"silver\"><font size=-1>" .
      
$arr[$i][5] . "</font></td>\n";
    }
  }
  echo
"</table></form>
  <!-- Finish the form with 2 more buttons: 'reset' and 'insert' -->
  <form target=\"_blank\"
   action=\"/PHP/db/db_process.php\" method=\"post\">
  <input type=\"submit\" name=\"insert\" VALUE=\"Insert New Data...\">
  </form>"
;
?>

  <hr>
  <div class="footer">
  <address>
    <a href="mailto&#058;Denice&#046;Deatrich&#064;epfl.ch">Denice Deatrich</a>
  </address>
<!-- Created: Sat Jun  3 09:10:30 MEST 2000 -->
<!-- hhmts start -->
Last modified: Tue Jun  6 23:55:04 MEST 2000
<!-- hhmts end -->
  </div>
</body>
</html>