If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Junior Member
    Join Date
    Feb 2003
    Member #

    I've topics under each topic there are subtopics and under subtopic there are articles.

    First, I'm listing all the topic names and then I select a topic name inorder to show the subtopic names.Now, I check subtopic names and press the button delete.The subtopic names are deleted only if there are no articles under that subtopic else it has to show me a mesg.

    I've been trying with this code and i could'nt get it to work.Could somebody please help me.

    Thanks in advance
    PHP Code:
    include "dbconnection.oam";

    // if you have chosen subtopics to delete 

    $subtopic_id $HTTP_POST_VARS['SUBTOPIC_ID']; 
    $qry3 "SELECT SUBTOPIC_ID FROM subtopic WHERE SUBTOPIC_ID='$subtopic_id'"
    $result_3 mysql_query($qry3) or die(mysql_error()."<br />SQL: $qry3); 

    // begin the query 
    $sql "SELECT COUNT(*) AS count FROM articles WHERE SUBTOPIC_ID='$subtopic_id'"
    $result_sub mysql_query($sql) or die(mysql_error()."<br />SQL: $sql); 
        if ( 
    mysql_result$result_sub0'count' ) > ) { 
    'There are articles existing under this sub-topic'
        else { 

    // there are no articles - safe to delete 
    $qry4 "DELETE FROM subtopic WHERE subtopic_id IN('" implode("','"$HTTP_POST_VARS['to_delete']) . "')"
    $row_4 mysql_fetch_row($result_3) ){ 
       if( isset(
    $HTTP_POST_VARS[$row_4->SUBTOPIC_ID]) ){ 

    // the checkboxes were named for the subtopic_id 
    $qry4 .= "OR SUBTOPIC_ID=".$row_4->SUBTOPIC_ID

    // add this subtopic to the query string 


    mysql_query($qry4) or die(mysql_error()); 

    // get the list of topic names 
    $result_1=mysql_query($qry1) or die(mysql_error()); 
    // if you have chosen a topic, get the list of subtopics 
    $result_3=mysql_query($qry3) or die(mysql_error()); 


    <!--- create the topic select box ---> 
    <form name="topic_form" action="<?=$PHP_SELF?>" method="post"> 
       <select name="TOPIC_ID"> 
          <option value="">Choose a topic</option> 

    "<option value=\"".$row->TOPIC_ID."\">".$row->TOPIC_NAME."</option>"
       <input type="submit" value="Set Topic"> 
       <!--- include topic_ID for continuity ---> 
       <input type="hidden" name="TOPIC_ID" value="<?=$HTTP_POST_VARS['TOPIC_ID']?>"> 

    <!--- create the list of subtopics ---> 
    <form name="delete_form" action="<?=$PHP_SELF?>" method="post"> 
    // subtopics named for the subtopic_id (aids in ease of retrieval after submittal 
    echo "<input type=\"checkbox\" name=\"to_delete[]\" value=\"".$row_3->SUBTOPIC_ID."\">".$row_3->SUBTOPIC_NAME."<BR>";


       <input type="hidden" name="TOPIC_ID" value="<?=$HTTP_POST_VARS['TOPIC_ID']?>"> 
    <!--- "action" defined so there is a definite switch to determine if things should be deleted ---> 
       <input type="hidden" name="action" value="delete"> 
       <input type="submit" value="Delete"> 
    <INPUT TYPE="Button" VALUE="Back" 
    onClick="window.location= 'menu.php' "> 
    I also did some sort of de-bugging with this query:
    PHP Code:
     $sql "SELECT COUNT(*) AS count FROM articles WHERE SUBTOPIC_ID='$subtopic_id'"
    I removed the $subtopic_id and given the id number and I found it working.
    well, why does this does'nt work with $subtopic_id.

    Thanks once again


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 12:26 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: