Hi

I'm a moderate level PHP developer and I'm trying to move to asp.net for a project but finding this a very difficult and alien experience. The hole ASP.net world is so different from the traditional PHP/mysql way of doings things. My head hurts.

What I want to do is generate a table dynamically in ASP.net by running an sql query and then loading the results into an array then iterate through the array and extract the columns I want and store then as variables that can be used to generate the table dynamically. this seems really simple and it should be but I'm getting nowhere with this in asp.net, using c# in a visual studio environment. I don't want to use grid views or anything like that, Id rather try and to it entirely programaticaly.

The table is sort of like the front page of a forum and I have it working in a ruff php script as follows. Can anybody show me how to recreate this in asp.net and C#?

<?php
//connect to database
$user="root";
$password="no";
$database="test";
mysql_connect("localhost",$user);
@mysql_select_db($database)or die("Unable to connect to the database");//error trapping
$query="SELECT * FROM category";

mysql_query($query);
$result=mysql_query($query);
$num=mysql_numrows($result);

$i=0;

echo'<table class="forumMain" id="category" cellspacing="0" cellpadding="1" ><tr>';
    
    while ($i < $num) {
          
                  $id=mysql_result($result,$i,"id");
                $catname=mysql_result($result,$i,"category_name");                      
    
    
        $query2="SELECT * FROM list WHERE category_id =$id";
        $result2=mysql_query($query2);
        
               echo '<th id="forumHeading1">'.$catname.'</th>';
               echo '<th id="forumHeading2">Threads</th>';
               echo'<th id="forumHeading3">Posts</th>';
               echo'<th id="forumHeading4">Last Post</th>';
               echo"</tr>";
               
            
     while  ($rows = mysql_fetch_array($result2)){
    
        $mbname = $rows["mb_name"];    
            
            echo"<tr>";
                echo'<td class="forumRow">'.$mbname.'</td>';
                echo'<td class="forumRow">&nbsp;</td>';
                echo'<td class="forumRow" >&nbsp;</td>';
                echo'<td class="forumRow">&nbsp;</td>';
            echo"</tr>";
                          
                          }
           $i++;
        
        }
        echo"</table>";

mysql_close();        
?>
This article has been dead for over six months. Start a new discussion instead.