1

我有以下代码从数据库中获取选项,但现在它显示为:1 - eur 17.50。我想在本文中添加单词 day(表示 1 天)或 days(如果值大于 1),以便显示为:1 天 - 17.50 欧元或 6 天 - 80 欧元。如何实现这一点?

<form method="post" action="framemaat.php?lang=<?=$_SESSION['lang'];?>&naam=<?=$naam;?>&postcodehuisnummer=<?=$postcodehuisnummer;?>&fietskeuze=<?=$fietskeuze;?>&opties=<?=$opties;?>&optieid=<?=$optieid;?>">
        <h2><?=$lang['pagina3_dagen']?> <select id="dagen" name="dagen" style="width:75;" style="height:250px;">
            <?php
            $query="SELECT * FROM $tabel WHERE fietstype='$fietskeuze'";
            $result=mysql_query($query) or die ("Ophalen prijzen mislukt: ".mysql_error());

            while ($row=mysql_fetch_array($result)) {
            $dagen=$row[dagen];
            $prijs=$row[prijs];
                echo "<option>
                    $dagen - EUR: $prijs    
                </option>";
            }  
            ?> 
        </select>

        <input type="submit" name="Submit" value="Volgende">
</form>
4

1 回答 1

1

应该很简单。

 <?php
            $query="SELECT * FROM $tabel WHERE fietstype='$fietskeuze'";
            $result=mysql_query($query) or die ("Ophalen prijzen mislukt: ".mysql_error());

            while ($row=mysql_fetch_array($result)) {
            $dagen=$row[dagen];
            if($dagen>1){
               $dayString = " days";
               }else{
               $dayString = " day";
               }
            $prijs=$row[prijs];
                echo "<option>
                    $dagen $dayString - EUR: $prijs    
                </option>";
            }  
            ?> 
于 2013-03-12T22:47:48.650 回答