locked
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)) { ?>
    
    <tr>
    <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>
    </tr>
    
    <?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">
    <head>
    	<title>Benkyo Killer</title>
    </head>
    <body>
    
    
    	<-- foreach statement -->
    
    
    </body>
    </html>

    Here's web.config

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

    What is the syntax in this case?

    Thanks.

    Wednesday, January 21, 2015 3:55 AM

Answers

All replies