0

I am pulling out a date value in the format 2012-12-28 from a database and now I need to create a html li element using the date value.

The li elements are in the following form which have an id and calls two javascript functions.

<li id="date2012-12-28" onClick="showUser('2012-12-28'); getID(this.id);">2012-12-28</li>

In this example the date "2012-12-28" is a variable value from the database.

How can I construct a php query to generate these links dynamically?

For example

echo '<li id="' . $value . + "onClick="showUser('" . $value . "');" ....

Thanks

2
  • 1
    what is the type of result? you can use foreach or for or while Commented Oct 28, 2012 at 4:36
  • I am using a while loop at the moment. Commented Oct 28, 2012 at 5:06

1 Answer 1

1

With the result set you would iterate over it with a foreach, so something like:

<?php foreach($result as $row){?>
<li id="date<?=$row['date'];?>" onClick="showUser('<?=$row['date'];?>'); getID(this.id);"><?=$row['date'];?></li>
<?php } ?>

or

<?php 
foreach($result as $row){
    echo '<li id="date'.$row['date'].'" onClick="showUser(\''.$row['date'].'\'); getID(this.id);">'.$row['date'].'</li>';
}
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.