如何检索和显示基于URL和Product-ID的图像?

时间:2013-08-10 04:19:37

标签: php

我在这里发布我的代码.. 我一直得到错误:

Notice: Undefined index: Image URL in C:\wamp\www\mySql1.php on line 35..

我在pimage表中的网址值为:'c:\wamp\www\toy1.jpg'。我知道这是对的吗?非常感谢任何人的善意回应和帮助..

<html>
<head></head>
<body>
<?php
//open connection to MySQL Server
$connection = mysql_connect('localhost','root', '')
        or die ('Unable to connect to !');

// select database for use
mysql_select_db('we-toys') or die ('Unable to select database!');

$query = 'select * from product p, pimage p2 where p.pid=p2.imagepid';
$result = mysql_query($query)
        or die ('Error in query: $query. ' . mysql_error());

if (mysql_num_rows($result) > 0)
{
    echo '<table width = 100% cellpadding = 10 cellspacing = 0 border = 1>';
    echo '<tr><td><b>ID</b></td>
      <td><b>PName</b></td>
      <td><b>PGroup</b></td>
          <td><b>PType</‌​b></td>
          <td><b>Qty</b></td>
          <td><b>Image></b></td>';

    while ($row = mysql_fetch_row($result)) 
    { echo '<tr>
    <td>'.$row[0].'</td>
    <td>'.$row[2].'</td>
    <td>'.$row[4].'</td>
    <td>'.$row[5].'</td>
    <td>'.$row[6].'</td>
    <td><img src="'.$row['ImageURL'].'"></td>
    </tr>'; 
} 
echo '</table>'; 

}
        else
        {
            echo 'No rows found!';        
        }
        mysql_free_result($result);
        mysql_close($connection);
     ?>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

<?php echo '<table width = 100% cellpadding = 10 cellspacing = 0 border = 1>
<tr><td><b>ID</b></td>
<td><b>PName</b></td>
<td><b>PGroup</b></td>
<td><b>PType</‌​b></td>
<td><b>Qty</b></td>
<td><b>Image></b>
</td></tr>';
while ($row = mysql_fetch_array($result)) 
{ echo '<tr><td>'.$row[0].'</td>
<td>'.$row[2].'</td>
<td>'.$row[4].'</td>
<td>'.$row[5].'</td>
<td>'.$row[6].'</td>
<td><img src="'.$row['ImageURL'].'"></td></tr>'; } 
echo '</table>'; ?>