Total members 10262 | Gratitudes |It is currently Thu May 24, 2012 9:38 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: deleting using javascript
PostPosted: Wed Aug 17, 2011 3:14 pm 
Offline
Newbie
User avatar

Joined: Tue Aug 09, 2011 12:50 pm
Posts: 7
Has thanked: 0 time
Have thanks: 0 time

hi all,
i want javascript function to delete the selected records for the given php program below....
also i am not getting field values in correct order one field is more than its field...
kindly tell me how to do it......
Code:
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="";     // Mysql password
$db_name="test"; // Database name
$tbl_name="emp"; // Table name

// Connect to server and select databse.
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
$sql="SELECT * FROM emp";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td align="center" bgcolor="white"><strong>EmpNo</strong></td>
<td align="center" bgcolor="white"><strong>EmpName</strong></td>
<td align="center" bgcolor="white"><strong>Desig</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result, MYSQL_ASSOC))
{

?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['empno']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['empname']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['desig']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?php
// Check if delete button active, start this
if($_POST['delete'])
{
//print_r($_POST);
//exit;
for($i=0;$i<count($_POST['checkbox']);$i++)
{
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}

// if successful redirect to delete_multiple5.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=h_delete.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: deleting using javascript
PostPosted: Sat Aug 20, 2011 4:36 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
For the first part of deleting using javascript , i understood that you want to delete the records from screen , you can using the innerHTML attribute like this :
Code:
function delete()
    {
         document.getElementById('id').innerHTML="";     
     }


second part , it is not clear to me , but it seems there is a duplication on the checkbox list , if so , it should be a duplicate values in $rows['id'].

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  

 Similar topics
 JavaScript fade out problem
 javascript read file
 getting gst, pst total to diplay in my javascript form
 need help with javascript
 Javascript select menu validation issue
 validate age entered as selection box in javascript
 Trim string in JavaScript
 check array contains a value using javascript
 Javascript Multi-dimensional Arrays
 print clock using JavaScript

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 2 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team