<?php require_once('Connections/food.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_food = "-1";
if (isset($_POST['food'])) {
  $colname_food = $_POST['food'];
}
mysql_select_db($database_food, $food);
$query_food = sprintf("SELECT * FROM food WHERE f_name LIKE %s ORDER BY f_id ASC", GetSQLValueString("%" . $colname_food . "%", "text"));
$food = mysql_query($query_food, $food) or die(mysql_error());
$row_food = mysql_fetch_assoc($food);
$totalRows_food = mysql_num_rows($food);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ค้นหาอาหาร</title>
<style type="text/css">
body,td,th {
	font-family: "Angsana New";
	font-size: 16pt;
}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
}
</style>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="middle"><img src="pic/banner.png" width="1000" height="274" /></td>
  </tr>
  <tr>
    <td align="center" valign="middle"><ul id="MenuBar1" class="MenuBarHorizontal">
      <li><a href="index.php">หน้าแรก</a>        </li>
      <li><a href="#" class="MenuBarItemSubmenu">บันทึกข้อมูล</a>
        <ul>
          <li><a href="add_typefood.php">บันทึกประเภทอาหาร</a></li>
          <li><a href="add_food.php">บันทึกอาหาร</a></li>
        </ul>
      </li>
      <li><a class="MenuBarItemSubmenu" href="#">ค้นหาข้อมูล</a>
        <ul>
<li><a href="search_typefood.php">ค้นหาประเภทอาหาร</a></li>
          <li><a href="search_food.php">ค้นหาอาหาร</a></li>
        </ul>
      </li>
</ul></td>
  </tr>
  <tr>
    <td align="center" valign="middle"><p><img src="pic/search.png" alt="" width="98" height="98" /></p>
      <table width="800" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="365" align="right">ค้นหาเมนูอาหาร : </td>
          <td width="435"><form id="form1" name="form1" method="post" action="">
            <label for="food"></label>
            <input name="food" type="text" id="food" size="50" />
            <input type="submit" name="button" id="button" value="ค้นหา" />
          </form></td>
        </tr>
      </table>
      <br />
      <table width="950" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="94" align="center" valign="middle" bgcolor="#FFFF99"><strong>รหัสอาหาร</strong></td>
          <td width="221" align="center" valign="middle" bgcolor="#FFFF99"><strong>ชื่ออาหาร</strong></td>
          <td width="88" align="center" valign="middle" bgcolor="#FFFF99"><strong>ราคา</strong></td>
          <td width="85" align="center" valign="middle" bgcolor="#FFFF99"><strong>ขนาด</strong></td>
          <td width="99" align="center" valign="middle" bgcolor="#FFFF99"><strong>หน่วยนับ</strong></td>
          <td width="130" align="center" valign="middle" bgcolor="#FFFF99"><strong>รหัสประเภทสินค้า</strong></td>
          <td width="86" align="center" valign="middle" bgcolor="#FFFF99"><strong>สถานะ</strong></td>
          <td colspan="2" align="center" valign="middle" bgcolor="#FFFF99"><strong>จัดการระบบ</strong></td>
        </tr>
        <?php do { ?>
          <tr>
            <td align="center" valign="middle"><?php echo $row_food['f_id']; ?></td>
            <td align="center" valign="middle"><?php echo $row_food['f_name']; ?></td>
            <td align="center" valign="middle"><?php echo $row_food['f_price']; ?></td>
            <td align="center" valign="middle"><?php echo $row_food['f_size']; ?></td>
            <td align="center" valign="middle"><?php echo $row_food['f_unit']; ?></td>
            <td align="center" valign="middle"><?php echo $row_food['t_id']; ?></td>
            <td align="center" valign="middle"><?php echo $row_food['f_status']; ?></td>
            <td width="71" align="center" valign="middle"><a href="edit_food.php?f_id=<?php echo $row_food['f_id']; ?>"><img src="pic/edit.png" width="35" height="35" /></a></td>
            <td width="76" align="center" valign="middle"><a href="delete_food.php?f_id=<?php echo $row_food['f_id']; ?>"><img src="pic/delete.png" width="29" height="35" /></a></td>
          </tr>
          <?php } while ($row_food = mysql_fetch_assoc($food)); ?>
      </table>
    <p>&nbsp;</p></td>
  </tr>
  <tr>
    <td align="center" valign="middle"><img src="pic/footer.png" width="1000" height="135" /></td>
  </tr>
</table>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
</html>
<?php
mysql_free_result($food);
?>
