로그인 한 사용자가 주문한 내용을 확인하기 위해 PHP의 관리자 사용자를위한 기본 주문 목록을 작성했습니다.주문 목록/while 루프 PHP 문제
이 스크립트의 목적은 주문 세부 정보 (항목, 수량, 가격)와 사용자의 이름 및 성 ('주문 :'이있는 위치)을 검색하는 것입니다.
아래 스크립트는 주문 (및 둘 이상의 주문이있는 경우 주문)을 검색하고 항목, 수량 및 가격을 모두 확인한다는 점에서 모든 작업을 수행합니다.
그러나 사용자 이름과 성을 표시하지 않습니다.
내가 알고있는 문제는 이름을 표시하려고하는 것이 while 루프 외부에 있지만 약간 앉아 있어야한다는 것입니다. 어떤 제안? 코드는 다음과 같습니다 :
echo '<p>Order for:<strong>'.$row[2].' '.$row[3]
$row
변수가 아직 존재하지 않습니다 : 그것은 문제처럼 보인다
<?php
$page_title = 'View Individual Order';
include ('includes/header.html');
// Check for a valid user ID, through GET or POST.
if ((isset($_GET['id'])) && (is_numeric($_GET['id'])))
{ // Accessed through view_users.php
$id = $_GET['id'];
} elseif ((isset($_POST['id'])) && (is_numeric($_POST['id'])))
{ // Form has been submitted.
$id = $_POST['id'];
} else { // No valid ID, kill the script.
echo '<h1 id="mainhead">Page Error</h1>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
include ('./includes/header.html');
exit();
}
?>
<h1>Order Details</h1>
<?php
require_once ('database.php'); // Connect to the db.
// Retrieve the user's, order and product information.
$query = "SELECT us.users_id, us.users_sales_id, us.users_first_name, us.users_surname, us.users_dealer_name,
ord.order_id, ord.users_id, ord.total, ord.order_date,
oc.oc_id, oc.order_id, oc.products_id, oc.quantity, oc.price,
prd.products_id, prd.products_name, prd.price
FROM users AS us, orders AS ord, order_contents AS oc, products AS prd
WHERE ord.order_id=$id
AND us.users_id = ord.users_id
AND ord.order_id = oc.order_id
AND oc.products_id = prd.products_id
";
$result = mysql_query ($query) or die(mysql_error());
if (mysql_num_rows($result)) { // Valid user ID, show the form.
echo '<p>Order for:<strong>' . $row[2] . ' ' . $row[3] . ' </strong> </p>
<table border="0" style="font-size:11px;" cellspacing="1" cellpadding="5">
<tr class="top">
<td align="left"><b>Product</b></td>
<td align="center"><b>Price</b></td>
<td align="center"><b>Qty</b></td>
</tr>';
$bg = '#dddddd'; // Set the background color.
while($row = mysql_fetch_array($result, MYSQL_NUM)) { // WHILE loop start
$bg = ($bg=='#eaeced' ? '#dddddd' : '#eaeced');
echo '<tr bgcolor="' . $bg . '">';
echo '<td align="left">' . $row[15] . '</td>
<td align="center">' . $row[13] . ' pts</td>
<td align="center">' . $row[12] . '</td>
</tr>';
echo '';
}// end of WHILE loop
echo '</table>
<p> Here:</p>
<br><br>
<p><a href="view-all-orders.php"> << Back to Orders</a></p>
<p> </p>
<p> </p>
<p> </p>
';
} else { // Not a valid user ID.
echo '<h1 id="mainhead">Page Error</h1>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
}
mysql_close(); // Close the database connection.
?>
<p>Footer here</p>
<?php
include ('./includes/footer_admin_user.html'); // Include the HTML footer.
?>
하는 제
foreach
루프를 가지고 있나요? "버퍼"하지 않습니다 제대로 들여 쓰기를 배우십시오. 이와 같이 모든 곳에 간격을두고 코드를 읽는 것은 매우 어렵습니다. –내 사과, 다음에 할 것이다 :) – AdamMc