简体   繁体   中英

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. 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.

I think you need to add some more code in order to determine what the 500 error is from. But I can tell you that you are including your array vars incorrectly in the html strings. The correct way to echo an array var in a string is:

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

I'd assume it would be something else, like a htaccess problem. Trouble in php usually doesn't turn into a http 500 server error.

Is all your .htacces code ok? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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