0

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....

5
Contributors
6
Replies
23
Views
6 Years
Discussion Span
Last Post by pushpatiwari
0

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>
0

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..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.