php+mysql 問題

係php+mysql既環境下我想個combo box可以get current value from table A同時又可以get  option from table B咁我應該點做呢?

請各位大大,俾下意見啦

TOP

TOP

thx師兄

TOP

都係唔得喎,師兄.........

TOP

原帖由 普通人士 於 2009-4-4 18:04 發表
都係唔得喎,師兄.........


不如你打個example result出黎, 咁先有人幫到你

TOP

SELECT a.*, b.* FROM (TABLE_A a LEFT JOIN TABLE_B b ON a.field = b.field)

TOP

SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name

用左left join都唔得

TOP

原帖由 普通人士 於 2009-4-5 14:43 發表
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name

用左left join都唔得

你比 Source 睇睇

TOP

<html>
     <header>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     </header>
<?php require_once('Connections/db.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $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;
}
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE client SET contact_person=%s, tel_no=%s, district_name=%s WHERE client_name=%s",
                       GetSQLValueString($HTTP_POST_VARS['contact_person'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['tel_no'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['district_name'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['client_name'], "text"));

  mysql_select_db($database_db, $db);
  $Result1 = mysql_query($updateSQL, $db) or die(mysql_error());

  $updateGoTo = "/client_search.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
// header(sprintf("Location: %s", $updateGoTo));
}

$colname_clientset = "-1";
if (isset($_GET['client_id'])) {
  $colname_clientset = $_GET['client_id'];
}
mysql_select_db($database_db, $db);
$query_clientset = sprintf("SELECT * FROM client WHERE client_id = %s", GetSQLValueString($colname_clientset, "int"));
$clientset = mysql_query($query_clientset, $db) or die(mysql_error());
$row_clientset = mysql_fetch_assoc($clientset);
$totalRows_clientset = mysql_num_rows($clientset);

mysql_select_db($database_db, $db);
$query_districtset = "SELECT district.district_name FROM district LEFT JOIN client ON district.district_name=client.district_name order by district.district_name";
$districtset = mysql_query($query_districtset, $db) or die(mysql_error());
$row_districtset = mysql_fetch_assoc($districtset);
$totalRows_districtset = mysql_num_rows($districtset);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>?¡?©¡Œ値?/title>
</head>

<body>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="488" height="306" border="0">
    <tr>
      <td width="251"><s></s></td>
      <td width="227"><s></s></td>
    </tr>
    <tr>
      <td>Client ID</td>
      <td><?php echo $row_clientset['client_id']; ?></td>
    </tr>
    <tr>
      <td>Client Name</td>
      <td> <input name="client_name" type="text" id="client_name" value="<?php echo $row_clientset['client_name']; ?>"></td>
    </tr>
    <tr>
      <td>Contact Person</td>
      <td> <input name="contact_person" type="text" id="contact_person" value="<?php echo $row_clientset['contact_person']; ?>"></td>
    </tr>
    <tr>
      <td>Tel No</td>
      <td> <input name="tel_no" type="text" id="tel_no" value="<?php echo $row_clientset['tel_no']; ?>">      </td>
    </tr>
    <tr>
      <td>District Name </td>
      <td><label for="district_name"></label>
        <select name="district_name" id="district_name">
          <?php
do {  
?>
          <option value="<?php echo $row_districtset['district_name']?>"<?php if (!(strcmp($row_districtset['district_name'], $row_districtset['district_name']))) {echo "selected=\"selected\"";} ?>><?php echo $row_districtset['district_name']?></option>
          <?php
} while ($row_districtset = mysql_fetch_assoc($districtset));
  $rows = mysql_num_rows($districtset);
  if($rows > 0) {
      mysql_data_seek($districtset, 0);
          $row_districtset = mysql_fetch_assoc($districtset);
  }
?>
                        </select></td>
    </tr>
  </table>
  <p>
    <input type="submit" name="Submit" value="Submit">
    <input name="Cancel" type="reset" id="Cancel" value="Cancel">
    <a href="/client_search.php">Return To Search Page</a></p>
  <p>&nbsp;</p>
  <p>&nbsp; </p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <input type="hidden" name="MM_update" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($clientset);

mysql_free_result($districtset);
?>

</html>

TOP