How do I use the foreach loop in my webpage? RRS feed

  • Question

  • User211148926 posted

    Hello everyone,

    I can't figure out how to use the foreach loop for displaying the table contents from my db, I've done it with PHP/MySQL like so:

    <?php while($subject = mysqli_fetch_assoc($result)) { ?>
    <td><?php echo $subject["id"]; ?></td>
    <td><?php echo $subject["menu_name"]; ?></td>
    <td><?php echo $subject["position"]; ?></td>
    <td><?php echo $subject["visible"]; ?></td>
    <td><?php echo $subject["content"]; ?></td>
    <?php } ?>

    With $result being the result of the query.

    Here's index.cshtml

        var db = Database.Open("benkyo_db");
        var query = "SELECT * FROM blos";
        var row = db.Query(query);
    <!DOCTYPE html PUBLIC "-//W3C//Dli HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dli">
    <html lang="en">
    	<title>Benkyo Killer</title>
    	<-- foreach statement -->

    Here's web.config

    <?xml version="1.0" encoding="UTF-8"?>
        <add name="benkyo_db" connectionString="Server=RAUL-PC\SQLEXPRESS; Database=buma; User Id=mumbai; Password=secretpassword;" providerName="System.Data.SqlClient"/>
        <directoryBrowse enabled="true" />

    What is the syntax in this case?


    Wednesday, January 21, 2015 3:55 AM


All replies