-5

我是 php 新手。不知道如何使用表达式。这是我网站搜索文件中的 php 代码。我想添加 html 标签,例如 href、div、li、ul 等。我该怎么做?

if(mysqli_num_rows($results) >= 1)
{
    $output = "";
    while($row = mysqli_fetch_array($results))
    {
        $output .= "Size: " . $row['fh_Vsize']. "<br />";
        $output .= "Icon: <img src=" . $path .$row['fh_Sicon']. " alt=><br />";
        $output .= "File ID: " . str_replace("_"," ",$row['fh_Sid']) . ""; $nbsp; $nbsp; $output .= "" . $row['fh_Vcaption'] . "<br />";
        $output .= "Description: " . substr(strip_tags($row['fh_Sdescription']),0,150) . "<br />";
        $output .= "Download: <a href=download_" . $row['fh_Sid'] . "/>Download</a><br /><br />";


    }
    echo  $output;
}
else
    echo "There was no matching record for the name " . $searchlink;

像这样的东西。我很抱歉这段代码。我是新来的,将学习基础知识:

<div class="info">
              <h4><a href="'. $path .'download_'. en_string($rec['fh_Sid']) .'/">'.de_string($rec['fh_Sid']) .' ' .$rec['fh_Vcaption'] .' '. $rec['fh_Vextension']. '</a><span class="updated">updated</span></h4>
             <div><img style="float:left;margin-right:5px" src="'. $path . str_replace("t_", "",$rec['fh_Sicon'] ).'"/></div><p>'. substr (strip_tags($rec['fh_Sdescription']),0,170) .' ...</p>
            <ul class="prod-info">
                <li class="none-separator">Last update: <strong>' . strftime("%d %b %Y", $rec['fh_Vdate']) . '</strong></li>
                <li>License: <a href="freeware_pop.html" title="'. $rec['fh_Vlicense'] . '">'. $rec['fh_Vlicense'] . '</a></li>
                <li>Size: <strong>'.$rec['fh_Vsize'].'</strong></li>
                <li>Downloads: <strong>'. $views[$sid] .'</strong></li>
                <li><img src="../../images/dl.png"/>&nbsp;<a href="'.$path.'download_'.$rec['fh_Sid'].'/">Download</a></li>
            </ul>
        </div>
4

2 回答 2

0

I prefer this way, which will let you have both php and html in their own format and easy to update:

<?php
if(mysqli_num_rows($results) >= 1)
{
    while($row = mysqli_fetch_array($results))
    {
    ?>
        <div class="info">
              <h4><a href="<?=$path .'download_'. en_string($rec['fh_Sid'])?>/"><?=de_string($rec['fh_Sid']) .' ' .$rec['fh_Vcaption'] .' '. $rec['fh_Vextension']?></a><span class="updated">updated</span></h4>
             <div><img style="float:left;margin-right:5px" src="<?=$path . str_replace("t_", "",$rec['fh_Sicon'] )?>"/></div><p><?=substr (strip_tags($rec['fh_Sdescription']),0,170)?> ...</p>
            <ul class="prod-info">
                <li class="none-separator">Last update: <strong><?=strftime("%d %b %Y", $rec['fh_Vdate'])?></strong></li>
                <li>License: <a href="freeware_pop.html" title="<?=$rec['fh_Vlicense']?>"><?=$rec['fh_Vlicense']?></a></li>
                <li>Size: <strong><?=$rec['fh_Vsize']?></strong></li>
                <li>Downloads: <strong><?=$views[$sid]?></strong></li>
                <li><img src="../../images/dl.png"/>&nbsp;<a href="<?=$path.'download_'.$rec['fh_Sid']?>/">Download</a></li>
            </ul>
        </div>
    <?php
    }
}
else
    echo "There was no matching record for the name " . $searchlink;
?>
于 2013-05-14T14:41:43.683 回答
0

对不起,这不是完整的代码,但基本上你可以使用这样的东西

while ($line1 = mysqli_fetch_object($result2)) 
{
$i=0;

$id = $line1->$index; // fetching the whole object id of the SQL table

    foreach ($line1 as $value1) 
    {   
        list($idName,$ext) = explode(".",$value1);
        if ($i==1) // to show only the icon name
        {   
        echo '
        <li id='.$value1.'  name="'.$id.'">
        <form id="addchart'.$idName.'" action="addchart.php" target = "_self" method="post">
        <a id='.$idName.'  onmousedown = "AddorDelete(this.id,this.value)" href = "#" value='.$idName.'>
        <img id="picture" class="icon"  src="images/item/php.png" width="70" style="margin: 0px 0px 0px 0px"/>
        <input type="hidden" name="db" value="'.$db.'" />
        <input type="hidden" name="table" value="'.$table.'" />
        <input type="hidden" name="id" value="'.$id.'" />

如果您想使用您创建的预定义 PHP 变量分配值、名称或 id,您可以echo 'html code and the attribute here' 小心分配值、名称或 id 的语法。

于 2013-05-14T14:12:03.483 回答