I'm displaying a set of rows here for every car I have in my database. Each row has a form field where a logged in user can submit an offer. When a user has made an offer for any car, the form field is replaced by a text displaying the value of the offer submitted.
What I'm experiencing, however, is less than ideal results. If I make an offer for one row, great, the logic works. If I go ahead and make another offer for another row then the logic works, except the fact that the previous row now displays the form again.
Gerekirse daha fazla ayrıntı sağlayabilir ama belki birileri bu aşinadır.
Şimdiden teşekkürler.
<?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; ?>