2012-03-13 3 views
1

を複製しています。それは良いです$ _POSTエコー..when ...しかし、私はPHPの変数に入れたときに、ユーザーが最初の選択により、出力が第二の窓になった後、それは

<? 

//list transactions by month 
if ($_POST['m']=="yes"){ 
$table = $_POST['month']; 
$_SESSION['table']=$_POST['month']; 

$conn = mysql_connect("localhost", "mss_records", "3205") or die(mysql_error()); 
mysql_select_db('store_records', $conn) or die(mysql_error()); 

$result = mysql_query("SELECT * FROM $table"); 

while($row = mysql_fetch_array($result)) 
{ 
$id=$row['transaction']; 
$date=$row['date']; 
$time=$row['time']; 
$paid=$row['payment']; 
$total=$row['total']; 
echo '<style type="text/css"> 
<!-- 
.list { 
font-family: Georgia, "Times New Roman", Times, serif; 
font-size: 12px; 
color: #000; 
padding: 2px; 
border: 2px solid #009; 
} 
.view { 
width: 100px; 
} 
--> 
</style> 
<div class="list"> 
<p><span style="color: #900">Transaction #</span>'.$id.' 
<span style="color: #900">Date:</span>'.$date.' 
<span style="color: #900">Time:</span>'.$time.'<span style="color: #900"> 
Paid By:</span>'.$paid.' <span style="color: #900">Total:</span>' 
.number_format($total, 2).' 
<form name="form1" method="post" action="find.php"> 
<label> 
<input type="submit" name="view" id="view" value="'.$id.'"> 
</label> 
</form> 
</p> 
</div> 
<p></p>'; 
} 
} 
//view transaction after viewing by month 
if (isset($_POST['view'])){ 


$conn = mysql_connect("localhost", "mss_records", "3205") or die(mysql_error()); 
mysql_select_db('store_records', $conn) or die(mysql_error()); 

$table = $_SESSION['table']; 
echo "this is the number ".$_POST['view']; 
$post=$_POST['view']; 
echo "this is the post ".$post; 
$result = mysql_query("SELECT * FROM $table WHERE transaction = '$post'") 
or die(mysql_error()); 

while($row = mysql_fetch_array($result)) 
{  
$items=$row['transaction']; 
} 
echo $items; 
} 
?> 

重複します。.. 。

this is the number 46this is the $post 4646 
+0

は[SSCCE](http://sscce.org/)を行うことを検討ので、我々はより明確にあなたのエラー – Jon

+0

Ιが、これはの重複に関係しているとは思わない見つけることができますあなたが言うように$ post変数。私は最後のエコー$ itemsと思う。ステートメントは46を印刷しているので、スクリプトが終了すると4646になります。スクリプトの最後のエコーをコメントアウトしてみてください。 – Andreas

答えて

1

q ueryはmysql_query("SELECT * FROM $table WHERE transaction = '$post'")です。したがって、$items=$row['transaction'];の値も46になります。改行なしですべてをエコーアウトすると、すべてが一気に壊れます。

POSTは何も複製していません。ちょうどその直後に$itemsをエコーし​​ています。

はこれを試してみてください:

$table = $_SESSION['table']; 
    echo "this is the number ".$_POST['view']."<br /> \n"; 
    $post=$_POST['view']; 
    echo "this is the post ".$post."<br /> \n"; 
    $result = mysql_query("SELECT * FROM $table WHERE transaction = '$post'") 
    or die(mysql_error()); 

    while($row = mysql_fetch_array($result)) 
    {  
    $items=$row['transaction']; 
    } 
    echo $items; 
    } 
+1

OMG ...私は眠るべきです...あなたは非常に正しいです...私は自分のコードで間違ったMYSQL行を持っています...前回の選択では、[トランザクション ']が表示され、この選択では、$ postは$ postのために選択された[items ']でなければなりません...だから私はそれを2回呼び出すだけでした....うわー...ありがとうございました!!!エコーは私がちょうど何が起こっていたのか把握しようとしていたので、それは改行なしでそれを悪化させた...笑 – dave

関連する問題

 関連する問題