无法在php中的表外显示数据库

时间:2008-11-28 14:32:17

标签: php html

我有这段代码

<?php
session_start();
if (isset($_GET["cmd"]))
  $cmd = $_GET["cmd"];
else
  die("You should have a 'cmd' parameter in your URL");
 $pk = $_GET["pk"];
$con = mysql_connect("localhost","root","geheim");
if(!$con)
{
die('Connection failed because of' .mysql_error());
}
mysql_select_db("ebay",$con);
if($cmd=="GetAuctionData")
{
echo "<table border='1' width='100%'>
<tr>
<th>Username</th>
<th>Start Date</th>
<th>Description</th>
</tr>";
$sql="SELECT * FROM Auctions WHERE ARTICLE_NO ='$pk'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
echo "<tr>
<td>".$row['USERNAME']."</td>
<td>".$row['ARTICLE_NO']."</td>
<td>".$row['ARTICLE_NAME']."</td>
<td>".$row['SUBTITLE']."</td>
<td>".$row['CURRENT_BID']."</td>
<td>".$row['START_PRICE']."</td>
<td>".$row['BID_COUNT']."</td>
<td>".$row['QUANT_TOTAL']."</td>
<td>".$row['QUANT_SOLD']."</td>
<td>".$row['ACCESSSTARTS']."</td>
<td>".$row['ACCESSENDS']."</td>
<td>".$row['ACCESSORIGIN_END']."</td>
<td>".$row['USERNAME']."</td>
<td>".$row['BEST_BIDDER_ID']."</td>
<td>".$row['FINISHED']."</td>
<td>".$row['WATCH']."</td>
<td>".$row['BUYITNOW_PRICE']."</td>
<td>".$row['PIC_URL']."</td>
<td>".$row['PRIVATE_AUCTION']."</td>
<td>".$row['AUCTION_TYPE']."</td>
<td>".$row['ACCESSINSERT_DATE']."</td>
<td>".$row['ACCESSUPDATE_DATE']."</td>
<td>".$row['CAT_1_ID']."</td>
<td>".$row['CAT_2_ID']."</td>
<td>".$row['ARTICLE_DESC']."</td>
<td>".$row['COUNTRYCODE']."</td>
<td>".$row['LOCATION']."</td>
<td>".$row['CONDITIONS']."</td>
<td>".$row['REVISED']."</td>
<td>".$row['PAYPAL_ACCEPT']."</td>
<td>".$row['PRE_TERMINATED']."</td>
<td>".$row['SHIPPING_TO']."</td>
<td>".$row['FEE_INSERTION']."</td>
<td>".$row['FEE_FINAL']."</td>
<td>".$row['FEE_LISTING']."</td>
<td>".$row['PIC_XXL']."</td>
<td>".$row['PIC_DIASHOW']."</td>
<td>".$row['PIC_COUNT']."</td>
<td>".$row['ITEM_SITE_ID']."</td>
<td>".$row['STARTS']."</td>
<td>".$row['ENDS']."</td>
<td>".$row['ORIGIN_END']."</td>
</tr>
<tr><td></td></tr>";

}
echo "</table>";
echo "<img src=".$row['PIC_URL'].">";
}
mysql_close($con);
?>

这是生成的html:

<table border='1' width='100%'>
<tr>
<th>Username</th>
<th>Start Date</th>
<th>Description</th>
</tr><tr>
<td>fashionticker1</td>
<td>220288560247</td>
<td>Ed Hardy Herren Shirt Rock & Roll Weiss XXL Neu & OVP</td>
<td></td>
<td>0.00</td>
<td>49.00</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>1.10.2008 16:22:09</td>
<td>6.10.2008 16:22:09</td>
<td>6.10.2008 16:22:09</td>
<td>fashionticker1</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>59.00</td>
<td>http://storage.supremeauction.com/flash/ebay2/10/49/76/10497654/13895964e.jpg</td>
<td>0</td>
<td>1</td>
<td>6.10.2008 16:21:47</td>
<td>6.10.2008 16:28:31</td>
<td>32315</td>
<td>0</td>
<td><!-- +++++++++++++++++++++++++ Bitte ändern Sie im eigenen Interesse nichts an diesem Code! ++++++++++++++++++++++++ -->
<!-- +++++++++++++++++++++++++ Das kann massive Fehldarstellungen ihrer Auktion zur Folge haben! +++++++++++++++++++ -->
<!-- +++++++++++++++++++++++++ ++++++++++++++++++++++++++ Ihr Supreme Team +++++++++++++++++++++++++++++++++++++++++ -->
</td>
<td>
<br>
<br>
<style ty</td>
<td>float: right;
</td>
<td>margin: 0px;
</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>padding:5px; 
</td>
<td>0.00</td>
<td>0.00</td>
<td>0.00</td>
<td>0</td>
<td>0</td>
<td>font-size: 12px;
</td>
<td>color: #333333;
}
#h</td>
<td>0000-00-00 00:00:00</td>
<td>0000-00-00 00:00:00</td>
<td>0000-00-00 00:00:00</td>
</tr>
<tr><td></td></tr></table><img src=>

无论我做什么,我都无法显示图像,当PIC_URL为空时,它只在表格上方显示占位符图像,我想在下面显示。

4 个答案:

答案 0 :(得分:1)

应该是:

echo "<img src=\"".$row['PIC_URL']."\">";

答案 1 :(得分:1)

<style ty</td>对我来说似乎是个问题。

答案 2 :(得分:1)

您正在生成while循环的标记 ,当$ row为false时结束。换句话说,当$ row因为你已经读完行而没有包含任何信息时,你才会到达那段代码!

输出图像的单元格,或输出带有单个单元格的新行,用于跨越整行的图像。

答案 3 :(得分:0)

while ($row = mysql_fetch_array($result))
{
*snip*
}
echo "</table>";
echo "<img src=".$row['PIC_URL'].">";

因为循环结束,$ row为false。您需要将其更改为类似的内容。

while ($row = mysql_fetch_array($result))
{
*snip*
$lastImg = $row['PIC_URL'];
}
echo "</table>";
echo "<img src=\"$lastImg\">";

我开始怀疑你有一个由yer数据库查询返回的有效PIC_URL。您应该尝试这一点,看看您是否从网址获得了任何有效的图片,特别是如果列表中的最后一个网址有效。

while ($row = mysql_fetch_array($result))
{
    *snip*
    $images[] = $row['PIC_URL'];
}
echo "</table>";
?><p>Are these valid urls you can open in yer browser?</p><pre><?php
    print_r($images);
?></pre><?php