php - Populate html markup with data from the database -
i'm trying translate between php , asp.net. in php can connect database, run query, , print out results in html tags shown below:
$query="select * comments;"; $result=$mysqli->query($query); while($row=$result->fetch_object()) { echo "<div class=\"comment\">"; echo "<h1>".$row->title."</h1>"; echo "<p>".$row->comment."</p>"; echo "</div>"; }
?>
in asp.net c#, how this?
i'm aware have use sqlconnection() , sqlcommand() , possibly sqldatareader(). how make asp.net have php doing above? , place code? in page load method? or in middle of html?
i have looked using grid views , table views pull data database, don't allow me make page how want. want data database populate html template mark up, not predefined grid or table structure.
thanks
i guess of in sql-server well. see below ....
test data
declare @comments table(title nvarchar(100), comment nvarchar(4000)) insert @comments values ('title 1', 'comments under tile 1'), ('title 2', 'comments under tile 2'), ('title 3', 'comments under tile 3')
query
select 'comment' [@class] ,title [h1] ,comment [p] @comments xml path('div');
result
<div class="comment"> <h1>title 1</h1> <p>comments under tile 1</p> </div> <div class="comment"> <h1>title 2</h1> <p>comments under tile 2</p> </div> <div class="comment"> <h1>title 3</h1> <p>comments under tile 3</p> </div>
Comments
Post a Comment