dsewbh5588 2016-05-15 02:25
浏览 73
已采纳

CSS没有在PHP页面中工作

I can't show my CSS into PHP pages:

I have this PHP page where i wrote my CSS (stile.php):

<?php
    header("Content-type: text/css");
    $url = "http://sitename.com/files/greenbutton.png";
    $colore = "#000000";
?>
a
{ background: <?echo $url;?>; 
color: <?echo $colore;?>;   }

This is my PHP page:

<html>
<head>
<title>Pagina dei Risultati</title>
<link rel="stylesheet" type="text/css" href="http://sitename.com/stile.php"/>
</head>


<title>Pagina dei Risultati</title>
<link rel="stylesheet" type="text/css" href="http://sitename.com/stile.php"/>


<?php
$db = mysql_connect('localhost','','') or die ('Impossibile connettersi');
mysql_select_db('my_palmiano', $db) or die(mysql_error($db));
$cognome=$_POST['cognome'];
$nome=$_POST['nome'];

if(empty($cognome) & empty($nome)) { ?>
<p align="center">Si deve inserire un Nome od un Cognome.</p>
<p align="center"><a href="http://sitename.com/cercaform.html">Torna alla pagina di Ricerca.</a></p>
<?php
exit();}


$sql = "SELECT * FROM Defunti WHERE cognome LIKE '%" . $cognome .  "%' AND nome LIKE '%" . $nome .  "%' ORDER BY cognome";
$result =mysql_query($sql, $db) or die (mysql_error($db));
$contatore= mysql_num_rows($result);
?>
<div style="text-align: center;">
<?php echo '<h2>'.'Risultati Trovati: '. $contatore.'</h2>';?>
<table border="1" bordercolor="black" cellpadding="2" cellspacing="2" style="width: 100%; margin-left: auto; margin-right: auto; text-align: center;">
<tr>
    <th>Cognome</th>
    <th>Nome</th>
    <th>Nascita</th>
    <th>Decesso</th>
    <th>Et&agrave</th>
    <th>Cimitero di</th>
    <th>Settore</th>
    <th>Numero</th>
    <th>Mappa</th>
    <th>Note</th>


</tr>
<?php

function calcola_eta($ggnascita,$mmnascita,$aaaanascita,$ggdecesso,$mmdecesso,$aaaadecesso){
    if ($ggnascita==0 || $mmnascita==0 || $aaaanascita==0 || $ggdecesso==0 || $mmdecesso==0 || $aaaadecesso==0){
        return 'ND';
    }
    if ($aaaanascita==$aaaadecesso ){
       return '-';}

     if ($aaaanascita<$aaaadecesso & $mmnascita < $mmdecesso){
       return (( $aaaadecesso - $aaaanascita) - 1);}

    if ($aaaanascita<$aaaadecesso & $mmnascita > $mmdecesso){
       return $aaaadecesso - $aaaanascita;
                    }
 if ($aaaanascita<$aaaadecesso & $mmnascita==$mmdecesso){
                        if ($ggnascita >= $ggdecesso) {
           return $aaaadecesso - $aaaanascita;
        } 
        if ($aaaanascita<$aaaadecesso & $mmnascita==$mmdecesso){
                        if ($ggnascita < $ggdecesso) {
                        return (( $aaaadecesso - $aaaanascita) - 1);}
          else { return 0;}
        }
    }}
while($row=mysql_fetch_array($result)){
extract($row);


echo '<tr>';
echo '<td>' . $cognome . '</td>';
echo '<td>' .  $nome. '</td>';
echo '<td>' . $ggnascita . '/'. $mmnascita . '/'. $aaaanascita . '</td>';
echo '<td>' . $ggdecesso . '/'. $mmdecesso . '/'. $aaaadecesso . '</td>';
echo '<td>' . calcola_eta($ggnascita, $mmnascita, $aaaanascita, $ggdecesso, $mmdecesso, $aaaadecesso). '</td>';
echo '<td>' . $localita . '</td>';
echo '<td>' . $settore . '</td>';
echo '<td>' . $numero . '</td>';
echo '<td>' . '<a href="http://palmiano.altervista.org/files/'. $settore . '.pdf'.'". target="_blank">' . 'visualizza'. '</a>'. '</td>';
echo '<td>' . $note . '</td>';
}
?>

</table>
</div>
</html>

Not minding for a moment about all those ifs and query injections (gonna correct later), why doesn't it show what i want to? Link to page stile.php is correct, i am afraid that is not the right position for <link rel="stylesheet" type="text/css" href="http://sitename.com/stile.php"/> or that html is too messed up....

  • 写回答

3条回答 默认 最新

  • douaipi3965 2016-05-15 08:09
    关注

    Expanding on to the Short Tags mistake, which is really not one (because it works in places where short tags are enabled), your CSS has a bigger syntax mistake:

    a { background: <?php echo $url;?>; color: <?php echo $colore;?>; }
    

    The above code render it as:

    a { background: http://sitename.com/files/greenbutton.png; color: #000000; }
    

    The above is a wrong value for background. You need to use:

    a { background: url('http://sitename.com/files/greenbutton.png'); color: #000000; }
    

    So, for that, change your PHP code to:

    a { background: url('<?php echo $url;?>'); color: <?php echo $colore;?>; }
    

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用