0
**<html>
<body>
<form name="call">
     <select name="category">
<option>Select a category</option>
<?php
 mysql_connect("localhost","root","");
 mysql_select_db("shenvel");
 $category = "SELECT productname FROM newproduct";
 //retrieving product name alone from newproduct
 $query_result = mysql_query($category);
 while($result = mysql_fetch_assoc($query_result))
{
    ?>
        <option value = "<?php echo $result['productname']?>"><?php echo $result['productname']?></option>  

//上面的代码显示一个空白的组合框作为输出。
**

4

4 回答 4

0

使用更改获取记录mysql_fetch_array()

while($result = mysql_fetch_array($query_result))
{
   *********
}

试试看。。

于 2013-03-11T05:45:53.330 回答
0

尝试这个

<select name="category">
<option>Select a category</option>
<?php
  mysql_connect("localhost","root","");
  mysql_select_db("shenvel");
  $category = "SELECT productname FROM newproduct";

  $query_result = mysql_query($category);
  while($result = mysql_fetch_array($query_result))
  {
 ?>
    <option value = "<?php echo $result['productname']; ?>"><?php echo $result['productname']; ?></option>  
  <?php
  }
  ?>
  </select>
于 2013-03-11T05:46:23.460 回答
0

尝试这个:

<html>
<body>
<form name="call">
     <select name="category">
<option>Select a category</option>
<?php
 mysql_connect("localhost","root","");
 mysql_select_db("shenvel");
 $category = "SELECT productname FROM newproduct";
 //retrieving product name alone from newproduct
 $query_result = mysql_query($category);
 while($result = mysql_fetch_array($query_result))
{
    ?>
        <option value = "<?php echo $result['productname']?>"><?php echo $result['productname']?></option>  
于 2013-03-11T05:47:29.963 回答
-1

您的 while 循环正在第一个<?php ... ?>片段中完全执行。您用于 while 循环的语法不会跨多个 php 代码片段执行。

尝试回显您的选项 HTML 代码,因此只有一个 php 代码片段。

<html>
<body>
<form name="call">
<select name="category">
  <option>Select a category</option>
  <?php
    mysql_connect("localhost","root","");
    mysql_select_db("shenvel");
    $category = "SELECT productname FROM newproduct";
    //retrieving product name alone from newproduct
    $query_result = mysql_query($category);
    while ($result = mysql_fetch_assoc($query_result)) {
      echo '<option value = "',  $result['productname'], '">', $result['productname'], '</option>';
    }
  ?>
于 2013-03-11T05:48:29.320 回答