0

このコードは、データベース内の 2 つのテーブルを結合します。whileループを使用してエコーしようとしてもエラーメッセージは表示されませんでしたが、何も表示されません。誰でも私を助けてもらえますか?

$sql = "SELECT * FROM usr_details, paymnt_details WHERE usr_details.Trnsnubr = paymnt_details.Trnsnubr";

$sql = 
"SELECT *
FROM usr_details 
JOIN paymnt_details ON usr_details.Trnsnubr = paymnt_details.Trnsnubr";  

これは、エコー用の私のhtmlおよびPHPコードです。

$rs_result = mysql_query ($sql) or die(mysql_error()); 
<table width="100%" height="109" border="1" cellpadding="2px" >
  <tr>
    <td colspan="5" class="mainheader">Registerd Persons</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="16"></td>
  </tr>
 <tr>
    <td class="tableheader" width="68">Payment</td>
    <td class="tableheader" width="64">Amount</td>
    <td class="tableheader" width="58">Date</td>
    <td class="tableheader" width="74">Trnsnubr</td>
    <td class="tableheader" width="97"> Paymenttyp </td>
    <td class="tableheader" width="59">Room Type</td>
    <td class="tableheader" width="96"> Packgname </td>
    <td class="tableheader" width="142">Full name</td>
    <td class="tableheader" width="1"> Email </td>
    <td class="tableheader" width="1">Mobile </td>
    <td class="tableheader" width="1">Address</td>
    <td class="tableheader" width="1">Country</td>
    <td class="tableheader" width="40">Mem_num</td>
    <td class="tableheader" width="40">Chptr</td>
    <td class="tableheader" width="40">Ral</td>
    <td class="tableheader" width="40">ex-mem-1-name</td>
    <td class="tableheader" width="40">ex-mem-2-name</td>
    <td class="tableheader" width="40">Faly-mem-1-name</td>
    <td class="tableheader" width="40">Faly-mem-2-name</td>
    </tr>
<?php 
while ($row = mysql_fetch_assoc($rs_result)) { 
$amount=$row["amount"];
$successness=$row["successness"];
$Timestamp=$row["Timestamp"];
$fname=$row["fname"];
$lname=$row["lname"];
$memnumbr=$row["memnumbr"];
$chptrpostion=$row["chptrpostion"];
$ralpositin=$row["ralpositin"];
$adrs1=$row["adrs1"];
$adrs2=$row["adrs2"];
$city=$row["city"];
$cntry=$row["cntry"];
$MTelNo=$row["MTelNo"];
$email=$row["email"];
$Trnsnubr=$row["Trnsnubr"];
$packgname=$row["packgname"];
$rtype=$row["rtype"];
$paymenttyp=$row["paymenttyp"];
$exmem1name=$row["exmem1name"];
$exmem2name=$row["exmem2name"];
$familymem1name=$row["familymem1name"];
$familymem2name=$row["familymem2name"];


        ?> 
<tr>
<td>  dfgdfgfdgdfgdg<?php echo $successness;?></td>
<td> <?php echo $amount;?></td>
<td> <?php echo $Timestamp;?></td>
<td> <?php echo $Trnsnubr;?></td>
<td> <?php echo $paymenttyp;?></td>
<td> <?php echo $rtype;?></td>
<td> <?php echo $packgname;?></td>
<td> <?php echo $fname." ".$lname;?></td>
<td> <?php echo $email;?></td>
<td> <?php echo $MTelNo;?></td>
<td> <?php echo $adrs1." ".$adrs2." ".$city;?></td>
<td> <?php echo $cntry;?></td>
<td> <?php echo $memnumbr;?></td>
<td> <?php echo $chptrpostion;?></td>
<td> <?php echo $ralpositin;?></td>
<td> <?php echo $exmem1name;?></td>
<td> <?php echo $exmem2name;?></td>
<td> <?php echo $familymem1name;?></td>
<td> <?php echo $familymem2name;?></td>
</tr>
<?php 
}; 
?> 
</table>

これは私のコーディングファイル全体です:

<?php session_start();
$user_name = $_SESSION['username'];
$user_pass = $_SESSION['password'];
if ( $user_name == '' ) {
header('location:login.php');
exit();
 }
?>
<?php require_once('connection.php'); ?>
<?php require_once('function.php'); ?>
<!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>Untitled Document</title>
<link href="css/main.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/users.css" rel="stylesheet" type="text/css" media="all" />
<link href="../dojo/dojo/resources/dojo.css" type="text/css" media="all" />
<link href="../dojo/dijit/themes/nihilo/nihilo.css" type="text/css" media="all" />
<script type="text/javascript" src="../dojo/dojo/dojo.js" ></script>
<script src="js/navigation.js" type="text/javascript"></script>
<script type="text/javascript">

</script>
<style type="text/css">
.tableheader {
    font-size: 18px;
    font-weight: bold;
    color: #96C;
}
.mainheader {
    font-size: 24px;
    font-weight: bolder;
    color: #09F;
}
</style></head>

<body class="nihilo">
<span class="tableheader"></span>
<div id="wrap">
<!-- Enable when Ajax is loading -->
<div id="loading_wrap"></div>
<div id="loading"><img src="images/loading.gif" width="32" height="32" alt="loading" /><br />Loading...</div>
<!-- End loading  -->
  <div id="head">
    <div id="subHead"></div>
  </div>
  <div id="main">
<?php 
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
$limit= 5;
$start_from = ($page-1) * $limit; 
//$sql = "SELECT * FROM usr_details ORDER BY Trnsnubr ASC LIMIT $start_from, $limit "; 
//$sql = "SELECT * FROM usr_details, paymnt_details WHERE usr_details.Trnsnubr = paymnt_details.Trnsnubr";
/*$sql = 
"SELECT *
FROM usr_details 
JOIN paymnt_details ON usr_details.Trnsnubr = paymnt_details.Trnsnubr";*/
$sql = "SELECT usr_details.*, paymnt_details.amount, paymnt_details.successness
FROM usr_details 
JOIN paymnt_details ON usr_details.Trnsnubr = paymnt_details.Trnsnubr";
$rs_result = mysql_query ($sql) or die(mysql_error()); 
?> 
<table width="100%" height="109" border="1" cellpadding="2px" >
  <tr>
    <td colspan="5" class="mainheader">Registerd Persons</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="16"></td>
  </tr>
 <tr>
    <td class="tableheader" width="68">Payment</td>
    <td class="tableheader" width="64">Amount</td>
    <td class="tableheader" width="58">Date</td>
    <td class="tableheader" width="74">Trnsnubr</td>
    <td class="tableheader" width="97"> Paymenttyp </td>
    <td class="tableheader" width="59">Room Type</td>
    <td class="tableheader" width="96"> Packgname </td>
    <td class="tableheader" width="142">Full name</td>
    <td class="tableheader" width="1"> Email </td>
    <td class="tableheader" width="1">Mobile </td>
    <td class="tableheader" width="1">Address</td>
    <td class="tableheader" width="1">Country</td>
    <td class="tableheader" width="40">Mem_num</td>
    <td class="tableheader" width="40">Chptr</td>
    <td class="tableheader" width="40">Ral</td>
    <td class="tableheader" width="40">ex-mem-1-name</td>
    <td class="tableheader" width="40">ex-mem-2-name</td>
    <td class="tableheader" width="40">Faly-mem-1-name</td>
    <td class="tableheader" width="40">Faly-mem-2-name</td>
    </tr>
<?php 
while ($row = mysql_fetch_assoc($rs_result)) { 
$amount=$row["amount"];
$successness=$row["successness"];
$Timestamp=$row["Timestamp"];
$fname=$row["fname"];
$lname=$row["lname"];
$memnumbr=$row["memnumbr"];
$chptrpostion=$row["chptrpostion"];
$ralpositin=$row["ralpositin"];
$adrs1=$row["adrs1"];
$adrs2=$row["adrs2"];
$city=$row["city"];
$cntry=$row["cntry"];
$MTelNo=$row["MTelNo"];
$email=$row["email"];
$Trnsnubr=$row["Trnsnubr"];
$packgname=$row["packgname"];
$rtype=$row["rtype"];
$paymenttyp=$row["paymenttyp"];
$exmem1name=$row["exmem1name"];
$exmem2name=$row["exmem2name"];
$familymem1name=$row["familymem1name"];
$familymem2name=$row["familymem2name"];
?> 
<tr>
<td> <?php echo $successness;?></td>
<td> <?php echo $amount;?></td>
<td> <?php echo $Timestamp;?></td>
<td> <?php echo $Trnsnubr;?></td>
<td> <?php echo $paymenttyp;?></td>
<td> <?php echo $rtype;?></td>
<td> <?php echo $packgname;?></td>
<td> <?php echo $fname." ".$lname;?></td>
<td> <?php echo $email;?></td>
<td> <?php echo $MTelNo;?></td>
<td> <?php echo $adrs1." ".$adrs2." ".$city;?></td>
<td> <?php echo $cntry;?></td>
<td> <?php echo $memnumbr;?></td>
<td> <?php echo $chptrpostion;?></td>
<td> <?php echo $ralpositin;?></td>
<td> <?php echo $exmem1name;?></td>
<td> <?php echo $exmem2name;?></td>
<td> <?php echo $familymem1name;?></td>
<td> <?php echo $familymem2name;?></td>
</tr>
<?php 
}; 
?> 
</table>

</div>
 <div id="footer">
<?php include("footer.php"); ?>
 </div>
</div> 
</body>
</html>
4

1 に答える 1

1

これらのテーブルに同じ名前の列がある場合、このリクエストはエラーを引き起こします。列名ですべての値を取得しようとしたことが原因です。難しいクエリでは * を使用しないようにしてください。

このようにしてみてください:

SELECT usr_details.*, paymnt_details.field1, paymnt_details.field2
FROM usr_details 
JOIN paymnt_details ON usr_details.Trnsnubr = paymnt_details.Trnsnubr

1

<?
$res = mysql_query("SELECT * FROM usr_details LIMIT 1");
var_dump(  mysql_fetch_assoc($res) );
$res = mysql_query("SELECT * FROM paymnt_details LIMIT 1");
var_dump(  mysql_fetch_assoc($res) );
$sql = "SELECT usr_details.* FROM usr_details LEFT JOIN paymnt_details ON usr_details.Trnsnubr = paymnt_details.Trnsnubr";
$res = mysql_query($sql);
var_dump($res);
while($row=mysql_fetch_assoc($res)) {
    var_dump($row);
}
var_dump( mysql_error() );
?>
于 2012-05-24T15:08:49.910 に答える