简体   繁体   English

PHP的MySQL查询和显示结果问题

[英]php mysql query and display results problem

I am trying to query the mysql DB and if there is a picture for the record I would like to have that image displayed. 我正在尝试查询mysql数据库,并且是否有用于记录的图片,我想显示该图片。 If there is no picture associated with the record then there should be no image displayed and no broken image link showing on the page. 如果没有与记录关联的图片,则页面上应该没有图像显示,也没有断开的图像链接显示。

    if ($data['picture'] > 0)
    {
    echo "<td><img style='float: left; padding: 2px 7px 2px 0px;' src='../images/pictures/' .'"$data['picture']"'. .'"$data['message']"'. .'</td>
                          </tr>'";
    }
  else
    {
    echo ".'<td>'. .'"$data['message']"'. .'</td>
                          </tr>'";
                          }

I'm sure it's something pretty small that I'm missing but I cannot seem to find the problem. 我确定这是我所缺少的很小的东西,但似乎找不到问题。

Currently this page returns a 500 error when I try to view the page. 目前,当我尝试查看该页面时,此页面返回500错误。

I think you need to add some more code in order to determine what the 500 error is from. 我认为您需要添加更多代码以确定500错误的来源。 But I can tell you that you are including your array vars incorrectly in the html strings. 但是我可以告诉您,您在html字符串中错误地包含了数组变量。 The correct way to echo an array var in a string is: 回显字符串中的数组var的正确方法是:

echo "<td>html html".$phpCode['array']." html html</td>";

I'd assume it would be something else, like a htaccess problem. 我认为这会是另外一回事,例如htaccess问题。 Trouble in php usually doesn't turn into a http 500 server error. php中的问题通常不会变成http 500服务器错误。

Is all your .htacces code ok? 您所有的.htacces代码都可以吗? What does your log say? 您的日志怎么说?

Your quotes and concatenation are all wrong. 您的引号和连接都是错误的。

echo ".'<td>'. .'"$data['message']"'. .'</td>
                          </tr>'";

Should be 应该

echo '<td>'.$data['message'].'</td></tr>';

And

echo "<td>
      <img style='float: left; padding: 2px 7px 2px 0px;' src='../images/pictures/' 
      .'"$data['picture']"'. .'"$data['message']"'. .'</td>
                          </tr>'";

Should be: 应该:

echo "<td>
      <img style='float: left; padding: 2px 7px 2px 0px;' src='../images/pictures/'" 
      .$data['picture'].$data['message']."</td></tr>";

You also need to make sure you close your <img> tag. 您还需要确保关闭<img>标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM