Displaying image from database outside of table in php

I have this code

<?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);
?>

      

Here is the generated 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=>

      

No matter what I do, I cannot get the image to display and when the PIC_URL is empty it only displays the placeholder image above the table and I want it below.

0


source to share


4 answers


It should be:



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

      

+1


source


<style ty</td>

looks like a problem to me.



+1


source


You are generating this img tag outside of the while loop, which ends when $ row is false. In other words, you will reach this code when $ row does not contain any information because you have finished reading rows!

Either output a cell for an image, or output a new line with one cell for an image spanning the entire row.

+1


source


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

      

Since the loop has ended, $ row is false. You need to change it to something like.

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

      

I am starting to doubt that you have a valid PIC_URL returned by your database query. You should try this, see if you have the correct images from the url, and especially if the last url in the list is valid.

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

      

0


source







All Articles