Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试显示两个表中的数据(图像和文本)时出错_Php_Mysql - Fatal编程技术网

Php 尝试显示两个表中的数据(图像和文本)时出错

Php 尝试显示两个表中的数据(图像和文本)时出错,php,mysql,Php,Mysql,我试图显示数据库中的图像,但要么在浏览器“item_Details.php?itemID=1”上看到此消息,要么什么都没有 我到处寻找我做错了什么,但什么也找不到 以下是表格: 'CREATE TABLE `images` ( `imagesID` int(5) NOT NULL AUTO_INCREMENT, `itemID` int(5) NOT NULL, `categoryID` int(5) NOT NULL, `name` varchar(30) NOT NULL, `size` i

我试图显示数据库中的图像,但要么在浏览器“item_Details.php?itemID=1”上看到此消息,要么什么都没有

我到处寻找我做错了什么,但什么也找不到

以下是表格:

'CREATE TABLE `images` (
`imagesID` int(5) NOT NULL AUTO_INCREMENT,
`itemID` int(5) NOT NULL,
`categoryID` int(5) NOT NULL,
`name` varchar(30) NOT NULL,
`size` int(11) NOT NULL,
`type` varchar(30) NOT NULL,
`pix` blob NOT NULL,
PRIMARY KEY (`imagesID`),
KEY `categoryID` (`categoryID`),
KEY `images_ibfk_1` (`itemID`),
CONSTRAINT `images_ibfk_1` FOREIGN KEY (`itemID`) REFERENCES `items` (`itemID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `images_ibfk_2` FOREIGN KEY (`categoryID`) REFERENCES `categories` 
(`categoryID`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1'

'CREATE TABLE `items` (
`itemID` int(5) NOT NULL AUTO_INCREMENT,
`categoryID` int(5) NOT NULL,
`itemName` char(25) NOT NULL,
`item_Description` varchar(255) DEFAULT NULL,
`price` char(10) DEFAULT NULL,
`contactName` varchar(50) DEFAULT NULL,
`phone` char(15) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`submitDate` date NOT NULL,
`expireDate` date NOT NULL,
`website` char(25) DEFAULT NULL,
PRIMARY KEY (`itemID`) USING BTREE,
KEY `submitDate` (`submitDate`),
KEY `categoryID` (`categoryID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1'
以下是用于在新窗口中显示特定项目详细信息的代码:

classified.php

//Table 3 Electrical Items
$query3 = "SELECT * FROM {$table} WHERE categoryID='3'";
$result = mysql_query($query3);
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
if($numofrows == 0){
echo "<p class=spect>Electrical Items:</p><p>No entries yet</p> \n";
}
else{
echo"<table id=mytable cellspacing=0 summary=Items from almacen database>
<caption>Electricals: </caption>";
echo "<TR bgcolor=\"lightblue\"><TH>Item Name</TH><TH>Price</TH><TH>Posted On</TH></TR>\n"; 
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
$id=$row['itemID'];
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#F5FAFA\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"#FFFFFF\">\n";
} 
echo "<TD><a href='item_Details.php?itemID=<?php=$id; ?>' target = '_blank'>{$row['itemName']}</a></TD>
<TD>&pound;".number_format ($row['price'],2)."</TD><TD>".$row['submitDate']."</TD>\n";
echo "</TR>\n";
} } 
echo "</table><br/>";
$query1 = "SELECT * FROM images, items WHERE (images.itemID='$id' && items.itemID='$id')";
$result = mysql_query($query1);

while ($row = mysql_fetch_array ($result))
{
header("Content-type: ".$row['type']."");
//header("Content-Disposition: attachment; filename=".$row['name']."");
echo"<table>";
echo"<tr>";
echo"<td colspan='2'>
  <h2 style='font-size: large;'> ".$row['itemName']."</h2></td>\n";
echo "</tr>";
echo "<tr>";
echo"<td><img border='0' align='right' src='{$row['pix']}' alt='item Image' style='margin-left: 5px;'></td>\n";
echo"<tr>";
echo"<td colspan='2'>
   <div>     
         <b>Price: </b>&pound;" .number_format ($row['price'],2). "<br />
         <b>Posted On: </b>" .$row['submitDate']. "<br />\n
         </div><br>
<b>Description: </b><p>" .$row['item_Description']. "<p><br />
 <div ;='' style=clear: both;>
  <h4 style='font-size: medium;'>Contact details:</h4>
<b>Name: </b>" .$row['contactName']. "<br />
<b>E-mail: </b>".$row['email']." <br /><br />  
</div></td>\n";
echo"</tr>\n";
}
echo "</table><br/>";
//表3电气项目
$query3=“从{$table}中选择*,其中categoryID='3';
$result=mysql\u查询($query3);
//让我们获得结果中的行数,以便在for循环中使用它
$numorrows=mysql\u num\u rows($result);
如果($numorrows==0){
echo“

电气项目:

还没有条目

\n”; } 否则{ 回声“ 电工:“; 回显“发布在上的项目名称价格\n”; 对于($i=0;$i<$numorrows;$i++){ $row=mysql_fetch_array($result);//从结果集中获取一行 $id=$row['itemID']; if($i%2){//这意味着如果有余数 回音“\n”; }else{//如果没有余数,我们将执行else 回音“\n”; } 回声“ £;“.number_格式($row['price'],2)。”.$row['submitDate']。“\n”; 回音“\n”; } } 回声“
”;
item_details.php

//Table 3 Electrical Items
$query3 = "SELECT * FROM {$table} WHERE categoryID='3'";
$result = mysql_query($query3);
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
if($numofrows == 0){
echo "<p class=spect>Electrical Items:</p><p>No entries yet</p> \n";
}
else{
echo"<table id=mytable cellspacing=0 summary=Items from almacen database>
<caption>Electricals: </caption>";
echo "<TR bgcolor=\"lightblue\"><TH>Item Name</TH><TH>Price</TH><TH>Posted On</TH></TR>\n"; 
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
$id=$row['itemID'];
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#F5FAFA\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"#FFFFFF\">\n";
} 
echo "<TD><a href='item_Details.php?itemID=<?php=$id; ?>' target = '_blank'>{$row['itemName']}</a></TD>
<TD>&pound;".number_format ($row['price'],2)."</TD><TD>".$row['submitDate']."</TD>\n";
echo "</TR>\n";
} } 
echo "</table><br/>";
$query1 = "SELECT * FROM images, items WHERE (images.itemID='$id' && items.itemID='$id')";
$result = mysql_query($query1);

while ($row = mysql_fetch_array ($result))
{
header("Content-type: ".$row['type']."");
//header("Content-Disposition: attachment; filename=".$row['name']."");
echo"<table>";
echo"<tr>";
echo"<td colspan='2'>
  <h2 style='font-size: large;'> ".$row['itemName']."</h2></td>\n";
echo "</tr>";
echo "<tr>";
echo"<td><img border='0' align='right' src='{$row['pix']}' alt='item Image' style='margin-left: 5px;'></td>\n";
echo"<tr>";
echo"<td colspan='2'>
   <div>     
         <b>Price: </b>&pound;" .number_format ($row['price'],2). "<br />
         <b>Posted On: </b>" .$row['submitDate']. "<br />\n
         </div><br>
<b>Description: </b><p>" .$row['item_Description']. "<p><br />
 <div ;='' style=clear: both;>
  <h4 style='font-size: medium;'>Contact details:</h4>
<b>Name: </b>" .$row['contactName']. "<br />
<b>E-mail: </b>".$row['email']." <br /><br />  
</div></td>\n";
echo"</tr>\n";
}
echo "</table><br/>";
$query1=“从图像中选择*项,其中(images.itemID='$id'和&items.itemID='$id')”;
$result=mysql\u查询($query1);
while($row=mysql\u fetch\u数组($result))
{
标题(“内容类型:“.$row['type']”);
//标题(“内容处置:附件;文件名=“.$row['name']”);
回声“;
回声“;
回声“
“$row['itemName']。”\n”;
回声“;
回声“;
回音“\n”;
回声“;
回声“
价格:£;“.number_格式($row['Price'],2)。”
发布于:“.$row['submitDate']”,
\n
描述:“$row['item_Description']。”
联系方式: 名称:“.$row['contactName']”,
电子邮件:“.$row['email']。”

\n”; 回音“\n”; } 回声“
”;
如果我使用classified.php
,浏览器会在item\u Details.php页面上显示“item\u Details.php?itemID=1”


现在,如果写入
这是无效的:

您可以使用

我更喜欢后者,因为它更明确

旁白
我不确定您是否正在处理遗留应用程序,或者这是您正在编写的新代码。如果是新代码,您应该花一两天(或者更长时间,如果您负担得起的话)来研究一些更好的编码实践。我将从逻辑分离和演示开始。尝试阅读以下内容:

更新

实际上,读这篇文章会更好:

代码太多了,至少对我来说是这样。你能找出一个具体的问题吗?你能展示生成的HTML的一些相关部分吗(与PHP源代码相反)?太多的代码和细节了。总结是有用的。我会把Pekka和McWafflestix的评论更进一步,说:太多的意大利面不合我的口味了。您可能需要研究如何将逻辑与演示分离。这将使调试变得更容易。清除查询结果,以便查看问题是数据还是其他一些显示的噪音。我们通常通过调试这种冗长的代码获得报酬。它仍然在显示这条消息!!感谢这篇文章,我应该至少花一周的时间来改进我的编码,因为您可能会注意到我是php新手。我会接受你的建议。谢谢