我正在做一个非常简单的拍卖网站,我想让一个用户从竞拍一个项目时,他们已经是最高的出价,我想保持该项目不被显示。
我有一个名为bidhistory的表,它存储投标人的accountid。下面是我用来防止用户对自己的物品出价的东西。从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
)";

最佳答案

注:
你想列出所有要投标的项目,但你不想让用户对他/她自己的项目投标?我们可以做的是获取所有竞价项目,然后在您的if() else()中使用一个基本的while loop()语句来检查每个项目是否由用户拍卖。
如果你在<accountid表中使用username(拍卖),那么我们就容易得多了,这样我们就可以在索引的一部分将这个表连接到biditems表快得多。不过,我们可以使用account列将INNER JOIN表连接到biditems表(希望用户名都是唯一的)。
你可以这样做:

$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 */

确保在account文件中,查询仍然检查用户是否拍卖了他们正在查看的项目。
同样,不要使用usernameAPI,因为它已经deprecated了。

08-06 22:52