简体   繁体   English

在PHP中使用if语句来打印HTML

[英]Using if-statements in PHP to print HTML

I'm fairly new to PHP and I've been trying to construct some code to print basic HTML, however the code causes an error 500 whenever used. 我是PHP的新手,我一直在尝试构建一些代码来打印基本HTML,但是无论何时使用,代码都会导致错误500。 I am guessing it is a syntax error since I've tried the code in a couple of forms and nothing seems to work (including removing the database lookup and just trying to compare to set values to each other). 我猜这是一个语法错误,因为我已经尝试了几种形式的代码,似乎没有任何工作(包括删除数据库查找,只是尝试比较设置值彼此)。 The script needs to get a variable from the db, compare it to a set value and print the HTML if true, here is the code I am trying: 脚本需要从db获取变量,将其与设定值进行比较并打印HTML,如果为true,这是我正在尝试的代码:

<?php
    $db = &JFactory::getDBO();
    $id = JRequest::getString('id');
    $db->setQuery('SELECT #__categories.title FROM #__content, #__categories WHERE #__content.catid = #__categories.id AND #__content.id = '.$id);
    $category = $db->loadResult(); ?>
  <?php if strcmp($category,"Blog")==0 : ?>

      <div style="display: -webkit-inline-box" class="sharelogos">
        <a href="http://www.facebook.com/sharer.php?u=<?php echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" target="_blank">  <img src="/images/sharing-icons/facebook.png" width="30px" alt="Facebook" /></a>
      </div>

<?php endif; ?>

Any help will be appreciated, thanks! 任何帮助将不胜感激,谢谢!

You if is incorrect, try like this if不正确,请尝试这样

<?php if (strcmp($category,"Blog")==0) { ?>

      <div style="display: -webkit-inline-box" class="sharelogos">
        <a href="http://www.facebook.com/sharer.php?u=<?php echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" target="_blank">  <img src="/images/sharing-icons/facebook.png" width="30px" alt="Facebook" /></a>
      </div>

<?php } ?>

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

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