CODE I
PHP Code:
$sql 
"SELECT menusubjects.Subject, menusubjects.image
  FROM menusubjects"

$result mysql_query($sql$connection);
 if(!
$result){
  die(
"Database query failed:" mysql_error());}
 while (
$content mysql_fetch_array($result)) {
  echo 
"<table width=\"260\" height=\"100\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FF0033\" bgcolor=\"#FFFFFF\" style=\"float:left; position:relative; left:206px; top:
  300px; height:5px;\">
  <td width=\"95%\ height=\"10%\"> <table width=\"96%\" height=\"10%\"> <td style=\"width:100%\"><img src=\"../images/lineforheader.gif\" alt=\"gf\" width=\"100%\" /></td><tr><td bordercolor=\"#666666\" bgcolor=\"#D83607\" height=\"100%\" style=\" width:140px;\"><a href=\"#\">
      <div class=\"shoe2\" align=\"left\" style=\"background-image:url(../images/titleshoe.gif);\">" 
$content['Subject'] . "</div>
    </a></td></tr>
    <tr>
      <td  style=\"width:100%; background:#CC0000; height:2px;\"><a href=\"#\">" 
$content['image'] . "</a></td>
    </tr></table></td>
  </table></td>"
;
  } 
I want to connect those subjects to a table called regularmenu. I want that WHERE a user click on a Subject then it goes into the following while loop.

CODE II

PHP Code:
$submenu false
$cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null
$prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null

$sql 'SELECT id,Subject FROM menusubjects;'
$result mysql_query($sql); 

if(
$result && mysql_num_rows($result)!=0) { 
     
    echo 
'<ul id="nav-categories">'
     
    while(
$row mysql_fetch_assoc($result)) { 
         
        
$uri 'example1.php?subject='.urlencode($row['id']); 
        
$class = !is_null($cat) && $cat==$row['id']?' class="selected"':''
         
        echo 
"\t",'<li',$class,'><a href="',$uri,'">',$row['Subject'].'</a>'
             
        if(
$submenu==false && !is_null($cat) && $cat == $row['id']) { // line 58 
                 
            
$sql2 'SELECT id,platename FROM regularmenu WHERE menusubject_id = '.mysql_real_escape_string($cat).';'
            
$result2 mysql_query($sql2); 
                 
            if(
$result2 && mysql_num_rows($result2)!=0) { 
                     
                echo 
"\n\t\t",'<ul class="submenu">',"\n";     
                 
                while(
$row2 mysql_fetch_assoc($result2)) { 
                     
                    
$uri2 $uri.'&menu='.urlencode($row2['id']); 
                    
$class2 = !is_null($prod) && $prod==$row2['id']?' class="selected"':''
                     
                    echo 
"\t\t\t",'<li',$class,'><a href="',$uri2,'">',$row2['platename'],'</a></li>',"\n"
                 
                } 
                 
                echo 
"\t\t",'</ul> <!-- end of ul.submenu -->',"\n";     
                     
            } 
                 
            
$submenu true
             
        } 
             
        echo 
'</li>',"\n"
         
    } 
         
    echo 
'</ul> <!-- end of ul#nav-categories -->',"\n 


How would the code will serve as a transition from the Code I to Code II look like? A code that WHERE a user click on the “.$content[‘Subject’].” Code I showed Below then redirect it to code II showed above would be?.
PHP Code:
 <td bordercolor=\"#666666\" bgcolor=\"#D83607\" height=\"100%\" style=\" width:140px;\"><a href=\"#\">
      <div class=\"shoe2\" align=\"left\" style=\"background-image:url(../images/titleshoe.gif);\">" 
$content['Subject'] . "</div>
    </a></td></ 

As you notice in Code II there are two queries one for subjects and the other for regularmenu or Submenus which display below those subjects.

Thank you.