English 中文(简体)
• 如何用我方的表格数据进行下降?
原标题:How to make a dropdown with data from a mysql table?

我想通过从我的桌子上获取价值来缩小面积。 这部法律似乎并不奏效;它所勾画的都是在没有内容的情况下倒台的盒子,我如何能够做到这一点? 或者在这样做时是否有替代程序?

<?
$connection = mysql_connect("localhost", "root", "");
mysql_select_db("test", $connection);
$query = "SELECT full_name FROM test";
$names = mysql_query($query);
function dropDown($content, $result)
 {
while($row = mysql_fetch_row($result))
    {
        $name = $row[0];
        $content .= "<option value= $name >$name</option>";
    }
 }
$content=<<<EOT
           <html>
              <body>
                 <select name="name">
EOT;

dropDown($content, $names)

$content.=<<<EOT
                 </select>
              </body>   
            </html>          


EOT;

echo $content;
?>
最佳回答

页: 1 PHP不是你使用out<>/em>参数的C,仅仅因为它们有时是手法。

function dropDown($result, $fieldName)
{
    $content =   ;
    while($row = mysql_fetch_row($result)) {
        $name = $row[0];
        $content .= "<option value= $name >$name</option>";
    }
    return  <select name=" .$fieldName. "> .$content. </select> ;
}

$content =  <html><body> ;
$content .= dropDown($names,  name );
问题回答
    here database details      
  mysql_connect( hostname ,  username ,  password );
mysql_select_db( database-name );

     $sql = "SELECT username FROM userregistraton";
        $result = mysql_query($sql);

         echo "<select name= username >";
  while ($row = mysql_fetch_array($result)) {
   echo "<option value= " . $row[ username ] ." >" . $row[ username ] ."</option>";}
   echo "</select>";


      here username is the column of my table(userregistration)
     it works perfectly

or simply the code is 
        <?
         $sql = "SELECT * FROM userregistraton ";
             $result = mysql_query($sql); ?>


 <select name="username" id="username">
<option value="">Select user</option>
    <?php
        while ($row = mysql_fetch_array($result))
        { ?>
          <option value="<?php echo $row[ uid ]?>"         <?php    if($row[ uid ]==$_POST["username"]) echo "selected"; ?> >
   <?php echo $row[ username ];?></option>
   <?php
         } ?>

<?php echo $form->dropDownList($model, courseprefer , array(

 (*value in database table* => displaying value ,
 )); ?>

您可以人工添加这些内容,只是确保阵列中的第一个价值被列入数据库表。

避免错误!





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签