简体   繁体   English

动态填充无序列表

[英]Dynamically populating an UnOrdered List

I am attempting following code to populate an UnOrdered List dynamically. 我正在尝试以下代码来动态填充未排序列表。 The same type of code I am successfully using to populate a DropDown. 我成功用于填充DropDown的相同类型的代码。 But when I changed the tags to UnOrdered List, it is not working. 但是,当我将标签更改为“无序列表”时,它不起作用。 When run, it just displays some tags instead of the actual output. 运行时,它仅显示一些标签而不是实际输出。

Where is the error: 错误在哪里:

<?php
    require("dbconnection.php");
    require("dbaccess.php");

    $divName = $_GET['DivName'];
    $ulName = $_GET['ControlName'];
    $query = $_GET['SqlQuery'];
echo $query;exit;
    dbconnection::OpenConnection();
    $result = dbaccess::GetRows($query);
?>
<ul id="<?php echo $ulName; ?>" name="<?php echo $ulName; ?>">
<?php while($row=mysql_fetch_array($result))
{ ?>
    <li><?php echo $row[1]; ?>"></li>
<?php } ?>
</ul>

The code that I used to populate a DropDown is below: It works absolutely fine: 我用来填充DropDown的代码如下:绝对可以正常工作:

<?php
    require("dbconnection.php");
    require("dbaccess.php");

    $dropdownControlName = $_GET['DropDownControlName'];
    $query = $_GET['SqlQuery'];
    dbconnection::OpenConnection();
    $result = dbaccess::GetRows($query);
?>
<select id="<?php echo $dropdownControlName; ?>" name="<?php echo $dropdownControlName; ?>">
<option>Select from the list</option>
<?php while($row=mysql_fetch_array($result))
{ ?>

    <option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>

<?php } ?>
</select>

不知道PHP,但是这行在做什么:

echo $query;exit;

The error is here: 错误在这里:

<li><?php echo $row[1]; ?>"></li>

should be this: 应该是这样的:

<li><?php echo $row[1]; ?></li>

Are you sure that you have to use the second field of the result set? 您确定必须使用结果集的第二个字段吗?

    <li><?php echo $row[1]; ?>"></li> 

There is an extra >" there. 那里有一个额外的>"

Can you show us the resulting html code ? 您可以向我们展示生成的html代码吗?

SORRY: I was away from the PC for some minutes before posting, just saw that I answered the same as the following answer. 抱歉:发帖前我已经离开PC了几分钟,只是看到我的回答与以下答案相同。

HI, HI,

I used your code and gave some constant values and i got the following out put. 我使用了您的代码并给出了一些常量值,然后得到了以下结果。

Out Put: 输出:

  • 1"> 1" >
  • 2"> 2" >
  • 3"> 3" >
  • 4"> 4" >

    Used code: 使用的代码:

      ` `
    • "> “>
    • ` `

    and final Conclusion is, this prints the unordered list and i think yo may check your 最后的结论是,这将打印出无序列表,我认为您可能会检查您的

    echo $row[1]; echo $ row [1]; part for any html out puts. 任何html输出的部分。

    Note: "> This tag comes because of in your code having this value 注意:“>之所以使用此标记,是因为您的代码中具有此值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM