我在這裏顯示一組行,用於我在數據庫中擁有的每輛車。 每行都有一個表單字段,登錄用戶可以提交報價。 當用戶爲任何汽車提供報價時,表單字段會被顯示提交報價值的文本替換。基於用戶輸入顯示錶單域
什麼我遇到了,但是,是達不到理想的效果。 如果我爲一行提供優惠,那麼邏輯起作用。如果我繼續爲另一行提供另一個報價,那麼邏輯就起作用,除了上一行現在再次顯示錶單這一事實。
我可以提供更多的細節,如果有必要,但也許有人熟悉了。
在此先感謝。
<?php
require("db-connect.php");
$display = "SELECT filename, car_id, make, model, year, mileage, vin, description, GROUP_CONCAT(filename) FROM scraplis_cars LEFT JOIN scraplis_images USING (car_id) GROUP BY car_id ORDER BY date_time DESC";
$dResult = mysql_query($display) or die('error:' . mysql_error());
$offer = "SELECT car_id, user_id, offer_id, value FROM scraplis_offers WHERE user_id = '".$_SESSION['user_id']."'";
$oResult = mysql_query($offer) or die('Error ' . mysql_error());
$oRow = mysql_fetch_array($oResult);
if(!isset($_SESSION['access'])){
header("location:index.php");
}
?>
<?php if($dResult): ?>
<table class="post">
<thead>
<tr>
<?php if(isset($_SESSION['email']) && $_SESSION['access'] == 0) : ?>
<th scope="col">Images</th>
<th scope="col">Make</th>
<th scope="col">Model</th>
<th scope="col">Year</th>
<th scope="col">Mileage</th>
<th scope="col">VIN #</th>
<th scope="col">Description</th>
<th scope="col">Offer</th>
</tr>
</thead>
<tbody>
<?php while($dRow = mysql_fetch_array($dResult)) : ?>
<?php $str = $dRow[8]; ?>
<?php $images = explode(',', $str); ?>
<tr>
<td>
<ul>
<?php if(!empty($str)) : ?>
<?php foreach($images as $value) :?>
<li>
<a href="images/<?php echo $value; ?>" rel="lightbox[<?php echo $row['car_id']; ?>]">
<img src="images/<?php echo $value; ?>"/>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
<ul>
</td>
<td><?php echo $dRow['make']; ?></td>
<td><?php echo $dRow['model']; ?></td>
<td><?php echo $dRow['year']; ?></td>
<td><?php echo number_format($dRow['mileage']); ?></td>
<td><?php echo $dRow['vin']; ?></td>
<td><span><?php echo $dRow['description']; ?></span></td>
<td>
<?php if($oRow['car_id'] == $dRow['car_id']) : ?>
Offer pending approval - $<?php echo $oRow['value']; ?>
<?php else : ?>
<form id="offer" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<input type="text" id="price" name="offer" />
<input type="hidden" name="submitted" value="<?php echo $dRow['car_id']; ?>" />
<input type="submit" name="price" value="Submit" />
</form>
<?php endif; ?>
</td>
</tr>
<?php endwhile; ?>
<?php else : ?>
<th scope="col">Delete</th>
<th scope="col">Images</th>
<th scope="col">Make</th>
<th scope="col">Model</th>
<th scope="col">Year</th>
<th scope="col">Mileage</th>
<th scope="col">VIN #</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<?php while($dRow = mysql_fetch_array($dResult)) : ?>
<?php $str = $dRow[8]; ?>
<?php $images = explode(',', $str); ?>
<tr>
<td>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<input type="checkbox" name="record" value="<?php echo $row['car_id']; ?>" />
<input type="submit" name="delete-car" value="Delete" />
</form>
</td>
<td>
<ul>
<?php if(!empty($str)) : ?>
<?php foreach($images as $value) :?>
<li>
<a href="images/<?php echo $value; ?>" rel="lightbox[<?php echo $row['car_id']; ?>]">
<img src="images/<?php echo $value; ?>"/>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</td>
<td><?php echo $dRow['make']; ?></td>
<td><?php echo $dRow['model']; ?></td>
<td><?php echo $dRow['year']; ?></td>
<td><?php echo number_format($dRow['mileage']); ?></td>
<td><?php echo $dRow['vin']; ?></td>
<td><span><?php echo $dRow['description']; ?></span></td>
</tr>
<?php endwhile; ?>
<?php endif; ?>
</tbody>
</table>
<?php endif; ?>
爲什麼不加入您的優惠表?您似乎無法控制您爲給定行或循環帶回的優惠,只會將其全部返回給定用戶?在加入時,您可以爲該用戶獲取針對該車輛的最新報價。 – Scuzzy 2010-12-07 06:43:47