hi
i have a newslist table that shows all news titles being published.news are displayed using while loop.
i want to add a check box on left side of each news title, i want when users check multiple checkboxes,news id associated with theses checkboxes shold be taken and the selted news must be deleted from database
any one can help plz.
Regards....

Recommended Answers

Here i have written complete code.
Try it, its easy to understand.

<?
	mysql_connect('localhost','root','');
	mysql_select_db('test');	
	
	if(isset($_REQUEST['delete']))
	{
		$deleteCb = $_REQUEST['deleteCb'];
		for($i=0;$i<count($deleteCb);$i++)
		{
			$news_id = $deleteCb[$i];
			$q = "delete from newslist where news_id= ".$news_id;
			mysql_query($q);		
		}
		header("location:test.php");
		exit;
	}
?>
<form name="form" id="form" method="post">
<table width="400" border="1" cellspacing="0" …
Jump to Post

All 6 Replies

Here i have written complete code.
Try it, its easy to understand.

<?
	mysql_connect('localhost','root','');
	mysql_select_db('test');	
	
	if(isset($_REQUEST['delete']))
	{
		$deleteCb = $_REQUEST['deleteCb'];
		for($i=0;$i<count($deleteCb);$i++)
		{
			$news_id = $deleteCb[$i];
			$q = "delete from newslist where news_id= ".$news_id;
			mysql_query($q);		
		}
		header("location:test.php");
		exit;
	}
?>
<form name="form" id="form" method="post">
<table width="400" border="1" cellspacing="0" cellpadding="0">
<?
	$q="select * from newslist";
	$rs = mysql_query($q);		
	if(mysql_num_rows($rs))
	{
?>
	<tr>
		<td>Delete</td>
		<td>Title</td>
	</tr>
<?
	while($sar = mysql_fetch_assoc($rs))
	{
?>	
	<tr>
		<td><input name="deleteCb[]" type="checkbox" value="<?=$sar['news_id'];?>" /></td>
		<td><?=$sar['title'];?></td>
	</tr>
<? } ?>
	<tr>
		<td><input name="delete" value="Delete Selected" type="submit" /></td>
		<td>&nbsp;</td>
	</tr>	
<?	}
	else
	{
?>
	<tr>
		<td></td>
		<td>No result found</td>
	</tr>
<? } ?>		
</table>
</form>

thanks i tried this code and its working
thanks again

thanks i was working on this and this is helpfull.

hii..
iam new in this field thats why i don,t know the basics of php.if i want to update a table what coding i make,i practise a lot on this topic and i also research on it but after that i failed . when i click submit button it submit but i not got result,PLS tell me whre i did mistake.and iam very thankfull to you if you help in this..

pls send me the coding related to update table of database using php..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.