Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to delete from multiple table
    primarykey
    data
    text
    <p>I have 3 tables:</p> <ol> <li><p>table <code>events</code>. In this I have fields such as <code>event_id, user_id, title, email, location, address, latitude, longitude, description, isapproved</code></p></li> <li><p>table <code>event_time</code>. In this I have fields <code>show_id, event_id, start_date, start_time, end_date, duration, date, end_time</code></p></li> <li><p>table <code>category</code>: <code>id, cat_id, event_id</code></p></li> </ol> <p>I am inserting data into 3 tables so that if an event of <code>event_id</code> 5 is entered into the <code>event</code> table then the corresponding data will be filled in <code>event_title</code> and <code>category</code>. While filling <code>event_time</code> table if the events <code>start_time</code> is <code>2011-12-05</code> and <code>end_date</code> is <code>2011-12-07</code> then <code>event_time</code> table will filled with 3 rows like with same event id and different date:</p> <pre><code>show_id event_id start_date start_time end_date duration date end_time 11 5 2011-12-05 12:00:00 2011-12-07 03:00:00 2011-12-07 15:00:00 10 5 2011-12-05 12:00:00 2011-12-07 03:00:00 2011-12-06 15:00:00 9 5 2011-12-05 12:00:00 2011-12-07 03:00:00 2011-12-05 15:00:00 </code></pre> <p>The <code>category</code> table will be entered based on number of categories selected in category drop down list.</p> <pre><code>id cat_id event_id 25 3 5 24 5 5 </code></pre> <p>Now I want to delete the event from the database based on user choice. If he wants to delete the event of particular date then only in <code>event_time</code> it should get deleted in events, category it should be there. But if user wants to delete event not based on any date the data from all the table should be removed. </p> <pre><code>&lt;?php include_once("webconfig.php"); include_once("webdatabase.php"); $show_id = isset($_REQUEST['show_id'])?trim($_REQUEST['show_id']):""; $event_id = isset($_REQUEST['event_id'])?trim($_REQUEST['event_id']):""; if(isset($show_id)) { $s="select * from event_time where event_id='$event_id'"; $num_rows = mysql_num_rows($s); die($num_rows); $exe=$db-&gt;query($s); if($db-&gt;row_count()==1) { $sql ="Delete events,event_time,category from events join event_time join category on(events.event_id=event_time.event_id and event_time.event_id=category.event_id) where event_time.show_id='$show_id'"; $exe=$db-&gt;query($sql); $successMsg = "deleted Successfully! . "; $xml = '&lt;?xml version="1.0" encoding="utf-8"?&gt;'; $xml .= '&lt;root&gt;'; $xml .= '&lt;delete&gt;'; $xml .= '&lt;status&gt;True&lt;/status&gt;'; $xml .= "&lt;message&gt;$successMsg&lt;/message&gt;"; $xml .= '&lt;/delete&gt;'; $xml .= '&lt;/root&gt;'; echo $xml; } else { $sql1 ="Delete event_time from event_time where event_time.show_id='$show_id'"; e=$db-&gt;query($sql1); $successMsg = "deleted Successfully! . "; $xml = '&lt;?xml version="1.0" encoding="utf-8"?&gt;'; $xml .= '&lt;root&gt;'; $xml .= '&lt;delete&gt;'; $xml .= '&lt;status&gt;True&lt;/status&gt;'; $xml .= "&lt;message&gt;$successMsg&lt;/message&gt;"; $xml .= '&lt;/delete&gt;'; $xml .= '&lt;/root&gt;'; echo $xml; } } else { $xml = '&lt;?xml version="1.0" encoding="utf-8"?&gt;'; $xml .= '&lt;root&gt;'; $xml .= '&lt;delete&gt;'; $xml .= '&lt;status&gt;false&lt;/status&gt;'; $xml .= "&lt;message&gt;no data found&lt;/message&gt;"; $xml .= '&lt;/delete&gt;'; $xml .= '&lt;/root&gt;'; echo $xml; } ?&gt; </code></pre> <p>this is what the code i have written. Anyone know how to do this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload