RKh
RKh

Reputation: 14161

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. 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:

<?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>

Upvotes: 0

Views: 1783

Answers (4)

Ranga
Ranga

Reputation: 11

HI,

I used your code and gave some constant values and i got the following out put.

Out Put:

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

    Used code:

      `
    • ">
    • `

    and final Conclusion is, this prints the unordered list and i think yo may check your

    echo $row[1]; part for any html out puts.

    Note: "> This tag comes because of in your code having this value

Upvotes: 1

Edelcom
Edelcom

Reputation: 5058

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 ?

SORRY: I was away from the PC for some minutes before posting, just saw that I answered the same as the following answer.

Upvotes: 1

Karsten
Karsten

Reputation: 14642

The error is here:

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

should be this:

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

Upvotes: 1

Edelcom
Edelcom

Reputation: 5058

Don't know Php but what this line doing :

echo $query;exit;

Upvotes: 1

Related Questions