drxpt06820
2013-03-30 17:16
浏览 42
已采纳

PHP查询选项定义中的PHP下拉框

I have been trying to decipher the option part of this: echo "<option value='" . $row['PcID'] . "'>" . $row['PcID'] . "</option>"; taken from Populate a Drop down box.....

can someone kindly explain what the periods do? and why when i do this: print "<option value='".$wrow['week_num']."'>".$wrow['week_name']."</option><br> "; I only get only the week name in the list.

$wquery="select week_num,week_name from stats_week";
$wresult=mysql_query($wquery);
print "Select Week:<select name=Week_select><br>
";
while ($wrow=mysql_fetch_assoc($wresult)){
    print "<option value='".$wrow['week_num']."'>".$wrow['week_name']."</option><br>
";    
}
print "</select>";
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongshenjie3055 2013-03-30 17:19
    已采纳

    In PHP, the period is the concatentation operator. Putting the periods in tells PHP to concatenate strings, See this page:

    http://www.php.net/manual/en/language.operators.string.php

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • drj58429 2013-03-30 17:19

    The periods "break up" the string, and allow you to run PHP code (mainly variables/ternary operators/functions) in it's place, between them.

    It's also a method of joining strings. This is called Concatenation.

    See String Operators


    Also, you only see the week name in the list because that's the only output you've got between your <option></option> tags.

    Does this help,

    $wquery="select week_num,week_name from stats_week";
    $wresult=mysql_query($wquery);
    print "Select Week:<select name=Week_select>";
    while ($wrow=mysql_fetch_assoc($wresult)){
        print "<option value='".$wrow['week_num']."'>".$wrow['week_num']." - ".$wrow['week_name']."</option>
    ";    
    }
    print "</select>";
    

    This will display the week number and name in the list. I've also removed the <br /> tags after your select/options.

    Please familiarise yourself with HTML Selects/Options.

    评论
    解决 无用
    打赏 举报
  • dongyong2906 2013-03-30 17:20

    Replace with;

    print "<option value='{$wrow['week_num']}'>{$wrow['week_name']}</option><br>
    ";  
    

    This will print the correct values and not return the php in html

    You will also want to look at concatenation on the PHP documentation

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题