我正在制作一个非常简单的拍卖网站,我想让用户在他们已经是最高出价者时对某个项目进行出价,我想让该项目不被显示。
我有一张名为bidhistory的表格,用于存储投标人的收益。我在下面的内容是我用来阻止用户对自己的项目进行出价的内容。从bidhistory表中选择的正确语法是什么?我希望我足够清楚。
$sql="SELECT * FROM biditems WHERE NOT accountid = $accountid";
我的更多代码:
$accountid=$_SESSION['accountid'];
$sql=" SELECT * FROM biditems WHERE NOT accountid = $accountid";
$result=mysql_query($sql);
echo "Items for Auction";
$expireDay=new DateTime('2015-07-19 20:12:50');
$theDay=new DateTime('now');
$timeToEnd=$expireDay->diff($theDay);
echo $timeToEnd->format('%R%a days');
while($row=mysql_fetch_array($result)) {
$itemid=$row['itemid'];
$item=$row['biditem'];
$auctionby=$row['username'];
$description=$row['biddesc'];
echo "<ul>";
echo "<li>$item auctioned off by $auctionby. <br> Description: $description
<br>
<a href='acceptbid.php?itemid=$itemid&item=$item'>Place bid</a></li>";
echo "</ul>";
}
?>
这是我的桌子。
$sql = "CREATE TABLE account (
accountid INT(100) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL
)";
$sql = "CREATE TABLE biditems (
itemid INT(100) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
accountid INT(100),
biditem VARCHAR(30) NOT NULL,
biddesc tinytext,
dateadded DATETIME
)";
$sql = "CREATE TABLE bidhistory (
bidhistoryid INT(100) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
accountid INT(100),
biditemid INT,
bidprice INT NOT NULL,
biddate DATETIME
)";
答案 0 :(得分:0)
if() else()
内查看基本while loop()
对帐单,以检查每个项目是否由用户拍卖。accountid
表中使用username
{<1>}(拍卖)会更容易,这样我们就可以将此表连接到{ {1}}表格在索引方面更快更容易。尽管如此,我们仍然可以使用biditems
使用account
列将INNER JOIN
表连接到您的biditems
表(希望用户名都是唯一的 )。你可以使用它:
account
username
文件中的查询仍然检查他们正在查看的项目是否未被用户拍卖。$sql=" SELECT a.itemid, a.biditem, a.biddesc, b.accountid, b.username FROM biditems a INNER JOIN account b ON a.username = b.username";
/* THE QUERY ABOVE WILL FETCH ALL BID ITEMS */
$result=mysql_query($sql); /* EXECUTE THE QUERY */
echo "Items for Auction";
$expireDay=new DateTime('2015-07-19 20:12:50');
$theDay=new DateTime('now');
$timeToEnd=$expireDay->diff($theDay);
echo $timeToEnd->format('%R%a days');
while($row=mysql_fetch_array($result)) {
$itemid=$row['itemid'];
$item=$row['biditem'];
$auctionby=$row['username'];
$description=$row['biddesc'];
$auctionbyid = $row['accountid']; /* accountid OF THE AUCTION-ER */
$result2 = mysql_query($con,"SELECT accountid FROM bidhistory WHERE biditem = '$itemid' ORDER BY bidhistoryid DESC LIMIT 1");
while($row2 = mysql_fetch_array($result2)){
$checkauctionid = $row2['accountid'];
}
echo '
<ul>
<li>'.$item.' auctioned off by '.$auctionby.'<br>
Description: '.$desription.'<br>';
if($accountid != $auctionbyid && $accountid != $checkauctionid){ /* IF THE ITEM IS NOT AUCTIONED BY THE USER OR HE/SHE WAS NOT THE HIGHEST BIDDER */
echo '<a href="acceptbid.php?itemid='.$itemid.'&item='.$item.'">Place bid</a></li>';
} /* END OF IF $accountid IS NOT THE SAME WITH $actionbyid */
else { /* ELSE, IT MEANS THAT THIS ITEM IS HIS/HERS, SO HE/SHE CANNOT BID ON HIS/HER OWN ITEM OR THAT HE IS THE HIGHEST BIDDER FOR THIS ITEM */
echo 'Cannot Place Bid';
} /* END OF ELSE */
echo '</ul>';
} /* END OF WHILE LOOP */
API,因为它已经deprecated。