如何将行作为类回显?

时间:2014-09-23 06:37:38

标签: php mysql sql twitter-bootstrap

如何将行回显为class

我试图将一个类回应到一个引导程序图标,我尝试了所有内容,但似乎无法使它运行起来。

我希望我的脚本将我的MySQL的笑脸类添加到<i class=""></i>课程。根据搜索情况插入悲伤/幸福的笑容..

我附上了MySQL ..

的屏幕截图
include_once ('mad-forbind.php');

if(isset($_GET['mad'])){
    $mad =  trim($_GET['mad']) ;
$mad = mysqli_real_escape_string($dbc, $mad);

$query = "select navn,kalorier,fedt, kul, protein, smiley from vare where navn like '%$mad%' or kalorier like '%$mad%'";

//echo $query;
$result = mysqli_query($dbc,$query);
if($result){
    if(mysqli_affected_rows($dbc)!=0){
          while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
echo '<p> <b>'.$row['navn'].'</b> **My smiley here** Kalorier: '.$row['kalorier'].' Fedt: '.$row['fedt'].' Kulhydrater: '.$row['kul'].' Protein: '.$row['protein'].' </p>'   ;
    }
    }else {
        echo 'Vi kunne desværre ikke finde:"'.$_GET['mad'].'"';
    }

}
}else {
    echo 'Parameter Missing';
}

MySQL的屏幕截图:

3 个答案:

答案 0 :(得分:0)

在echo语句中尝试此代码//假设您已经在。$ row ['smiley']

中提取了笑脸数据
echo '<p> <b>'.$row['navn'].'</b> **My smiley here** Kalorier: '.$row['kalorier'].' Fedt: '.$row['fedt'].' Kulhydrater: '.$row['kul'].' Protein: '.$row['protein'].' <i class=\"'.$row['smiley'].'\"></i></p>'   ;

答案 1 :(得分:0)

这有助于您找到内联评论     

include_once ('mad-forbind.php');

if(isset($_GET['mad']))
{
    $mad =  trim($_GET['mad']) ;
    $mad = mysqli_real_escape_string($dbc, $mad);

    $query = "select navn,kalorier,fedt, kul, protein, smiley from vare where navn like '%$mad%' or kalorier like '%$mad%'";

    //echo $query;
    $result = mysqli_query($dbc,$query);

    if($result)
    {
        if(mysqli_affected_rows($dbc)!=0)
        {
            //create table here
            $table = '<table>';
            $table .= '<tr>';
            $table .= '<th>navn</th>';
            $table .= '<th>kalorier</th>';
            $table .= '<th>kul</th>';
            $table .= '<th>fedt</th>';
            $table .= '<th>protein</th>';
            $table .= '<th>smiley</th>';
            $table .= '</tr>';

              while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
              {
                $table .= '<tr>';
                $table .= '<td>'.$row['navn'].'</td>';
                $table .= '<td>'.$row['kalorier'].'</td>';
                $table .= '<td>'.$row['kul'].'</td>';
                $table .= '<td>'.$row['fedt'].'</td>';
                $table .= '<td>'.$row['protein'].'</td>';           
                $table .= '<td>'.$row['smiley'].'</td>';
                $table .= '</tr>';
              }

            $table .= '</table>';

            //display the table here
            echo $table;
        }
        else 
        {
            echo 'Vi kunne desværre ikke finde:"'.$_GET['mad'].'"';
        }

    }
}
else 
{
    echo 'Parameter Missing';
}

答案 2 :(得分:0)

$a = "color: red";
echo "<html><head><style>
p.intro {
    ".$a."
}
</style></head>
      <body><p class='intro'>aaaaaaaaaaaaa</p></body></html>";