Jump to content

[SOLVED] deleting in a while statement


contra10

Recommended Posts

hi i'm trying to allow my users to delete post while in a while statement

 

heres my code


<form action="" method="get" enctype="application/x-www-form-urlencoded">
        <table border= "1" id="results">
          
           <?php
	   		mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error());
	   
	   //This is your query again, the same one... the only difference is we add $max into it
$data_p = "SELECT * FROM post_profile WHERE userid = '$idp' ORDER BY ppid DESC";
$posts = mysql_query($data_p) or die(mysql_error()); 

//This is where you display your query results
while($info = mysql_fetch_array($posts)) 
{ 


$userpost= "{$info['post']}";
$updel= "{$info['ppid']}";
$usernamep= "{$info['postingusername']}";
$userdate= "{$info['datepost']}";

$text = ($userpost);
$newtext = wordwrap($text, 30, "<br />\n",true); 
if(isset($_POST['deletep'])){

 $deletem= "DELETE FROM `post_profile` WHERE `ppid` = '$updel'";
$deletemessage = mysql_query($deletem) or die(mysql_error());
}
	echo"<tr><td></td></tr>";
           echo" <tr><td>$newtext</td></tr>";
echo" <tr><td><FONT size='1'>Posted by $usernamep on $userdate</FONT></td><td>";
?>
			   <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
		   <input type='submit' name='deletep' value='delete'>
		   </form>
		   
<?php			
echo"</td></tr>";
} 
?>

Link to comment
Share on other sites

1) u r querying user table with user id so there will be only one record, why do u need while loop?

2) if its not user table and somethign else and returns more than one record, then what u r doing is fetching all records, and deleting it one by one. anyways all ur records for that user are going to be deleted, why not just delete them qith one query. while loop not required again !

Link to comment
Share on other sites

$updel is in while loop for all ids u r fetching from database. to delete specific post, you will have to take post id from user.

 

1) Show all posts to user using while loop. Each post will have a radio button. this should be ofcourse inside a form.

2) On submit, put value of radio button in $updel. dont do the while loop. just fire the delete query once with $updel and user_id (BTW where is user id coming from?) in the WHERE clause.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.