Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-20-2011, 10:45 AM   PM User | #1
oxxiz
New Coder

 
Join Date: Jan 2011
Location: Slovenia
Posts: 38
Thanks: 4
Thanked 0 Times in 0 Posts
oxxiz is an unknown quantity at this point
ajax deletion from database

Hello
What I'd like to do is, that when a user presses the "delete" button when deleting a friend, it would delete that friend from the database.
Current problems:
  • fetching the username from the friend to delete
  • deleting the friend (I'm still a beginner at AJAX)

should I use a href or a submit button? this is what I have (using a submit button, but I have no idea on how to fetch the specific friends username which needs to be deleted)

PHP Code:

while($row2 mysql_fetch_array($qwery))
{
$friend $row2['user_username'];
$pic mysql_query("SELECT * FROM users WHERE username='$friend'");
$picrow mysql_fetch_assoc($pic);

echo 
"<img src='".$picrow['imagelocation']."' width='10%'>"."<br />"."<a href='viewbuddy.php?username=".$row2['user_username']."&page=profile'>".$row2['user_username']."</a>"."<br />"."<input type='submit' value='delete' onclick='deleteBud();'>"."<p />";



This echoes the friends and a submit button saying "delete".

what should I do to delete them? do I need a seperate file, like delete.php or something?

have a nice day
oxxiz is offline   Reply With Quote
Old 06-20-2011, 10:54 AM   PM User | #2
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
Imo a more user friendly approach is to have a check box for each friend and the user then checks the check boxes for the friends they want to delete. This way you can delete multiple friends in one go rather than one friend at a time with a delete button for each friend.

When the friends to delete are all selected, the user can click a Delete selected friends button which then sends the userID linked to each check box to a server side script which then deletes the sent userID's and associated records from the database.

You can do all this with or without AJAX.

Reading your post it appears your next step could be working through the w3schools ajax tutorials to get the basics of ajax.
bullant is offline   Reply With Quote
Old 06-20-2011, 10:57 AM   PM User | #3
oxxiz
New Coder

 
Join Date: Jan 2011
Location: Slovenia
Posts: 38
Thanks: 4
Thanked 0 Times in 0 Posts
oxxiz is an unknown quantity at this point
that would be a better approach, you're right.
I already went through the w3schools ajax tutorial, but it has nothing about deleting (or deleting multiple users, posts, whatever with checkboxes) out of the database. And I want to do it with AJAX because it wouldn't need to refresh the page (I'm doing this website for myself, not a customer or friend).
oxxiz is offline   Reply With Quote
Old 06-20-2011, 11:10 AM   PM User | #4
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
Quote:
Originally Posted by oxxiz View Post
that would be a better approach, you're right.
I already went through the w3schools ajax tutorial, but it has nothing about deleting (or deleting multiple users, posts, whatever with checkboxes) out of the database.
The tutorial gives a basic demo on how to retrieve database information using ajax. The concept is the same whether you want to retrieve or delete records - the ajax function sends data to a server side script (PHP, ASP or whatever) which then performs the required tasks on a database and then returns any required data back to the ajax function.

In the link I posted, there is a schematic diagram of the ajax process which is the same whether you want to retrieve or delete records.

So in your case, you will need a php script that receives data from either 1 or multiple check boxes or a single delete button. That data (in this case userID's) is then inserted into an sql statement to delete the requested records for the sent userID's.
bullant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:43 AM.


Advertisement
Log in to turn off these ads.