Hello,

I'm displaying some topic names on a list box, based on the selection and when i hit a button, it displays the sub-topic names in another list box.fine, upto here.

Now, when i select a sub-topic, and hit this button, I want to show the article names and article author related to this sub-topic.

This articles table has topic_id, subtopic_id, article_id and so on....
Also, could you please tell me where should i place the form fields to show the article names and article content??

Do i need to loop them through array???I commented my code well, so somebody can easily point out where exactly i can modify it.

Many thanks

PHP Code:

<?php 
//DB connection details 
include "../dbconnection.php";

?> 
<html> 
<head> 
<title>Delete articles</title> 
</head> 
<body>     

<?php 

// If the Change button is pressed. 
if (isset($_POST["send"])) 

// Check to see that the user selected an item from the topics. 
    
if(isset($_POST["TOPIC_ID"])) 
    { 
    
    
$TOPIC_ID = (int)$_POST["TOPIC_ID"]; 
    
$q mysql_query("select * from topic where TOPIC_ID=$TOPIC_ID"); 
         
        if (!
mysql_num_rows($q)) 
        
$TOPIC_ID 0;       
    } 
    else {   
            
$TOPIC_ID 0;   
         }    
     
// If the user has selected a topic and a subtopic. 
   
if((isset($TOPIC_ID)) && (isset($_POST["SUBTOPIC_ID"]))) 
   { 
   
$SUBTOPIC_ID = (int)$_POST["SUBTOPIC_ID"]; 
   
$q mysql_query("select * from subtopic where TOPIC_ID=$TOPIC_ID and SUBTOPIC_ID=$SUBTOPIC_ID"); 
      
       if (!
mysql_num_rows($q)) 
    
$SUBTOPIC_ID 0
   } 
   else { 
            
$SUBTOPIC_ID 0
 
         }       
     
//If the user has selected the topic, subtopic, print the article names and article content    
//I'm not sure if this part of the code is correct...
    
if ((isset($TOPIC_ID)) && (isset($SUBTOPIC_ID)) && (isset($_POST["ARTICLE_ID"])))  
    
$select_sql "select ARTICLE_NAME, ARTICLE_CONTENT from articles where SUBTOPIC_ID=$SUBTOPIC_ID";
    
$result_id mysql_query($select_sql) or die('Error retrieving records from articles.<br />Mysql Reported: '.mysql_error());
// Till here........... 
}
// If we got here, we need to display the form... 

echo "<form method=post action=\"$PHP_SELF\">"
echo 
"<select name=TOPIC_ID>"

$q mysql_query("SELECT * FROM topic ORDER BY TOPIC_NAME"); 
while (
$l mysql_fetch_array($q)) 

     
$selected=""
     if (
$l["TOPIC_ID"] == $TOPIC_ID
         
$selected "selected=1"
     echo 
"<option value=\"".$l["TOPIC_ID"]."\" $selected>".$l["TOPIC_NAME"]; 


echo 
"</select><br><br>"

echo 
"<select name=SUBTOPIC_ID>"
    if (
$TOPIC_ID
    { 
    
$q=mysql_query("SELECT * FROM subtopic WHERE TOPIC_ID=$TOPIC_ID"); 
    while (
$l=mysql_fetch_array($q)) 
        { 
        
$selected=""
        if (
$l["SUBTOPIC_ID"]==$SUBTOPIC_ID
            
$selected="selected=1"
        echo 
"<option value=\"".$l["SUBTOPIC_ID"]."\" $selected>".$l["SUBTOPIC_NAME"]; 
        } 
    } else { 
     echo 
"<option value=0>Please select topic first"
           } 
echo 
"</select><br><br>"

echo 
" <input type=submit name=send value=\"Change\"> "
echo 
"</form>"

?>
</body> 
</html>