vinpkl Posted November 20, 2008 Share Posted November 20, 2008 hi all I m working in admin section. There i have order details rows. i have a option of deleting the record on clicking the delete button with each row. Everytime when i click delete button it deletes the record that is on no.1 not the particular record that i selected. whether i select the delete button at row 5 then also it deletes the record of row 1. this the code <?php if(isset($_REQUEST['del_item_x'])) { $qry_del="select * from order_detail_table"; $result_del=mysql_query($qry_del); $row_del=mysql_fetch_array($result_del); $order_id=$row_del['order_id']; $product_name=$row_del['product_name']; //echo "test". $row_del['order_id']; $qry_del="DELETE from order_detail_table where product_name='$product_name'"; echo $qry_del; if(mysql_query($qry_del)) { $msg="item deleted success"; } else { $msg="item not deleted"; } } ?> vineet Link to comment https://forums.phpfreaks.com/topic/133446-problem-deleting-particular-row-record/ Share on other sites More sharing options...
Goldeneye Posted November 20, 2008 Share Posted November 20, 2008 Did you try using the order_id inside the query itself? I also hope you're not only echoing the $qry_del for development purposes. Link to comment https://forums.phpfreaks.com/topic/133446-problem-deleting-particular-row-record/#findComment-694100 Share on other sites More sharing options...
vinpkl Posted November 20, 2008 Author Share Posted November 20, 2008 hi golden eye i tried using order_id inside the qry this is the code <?php if(isset($_REQUEST['del_item_x'])) { $qry_del="select * from order_detail_table"; $result_del=mysql_query($qry_del); $row_del=mysql_fetch_array($result_del); $order_id=$row_del['order_id']; $product_name=$row_del['product_name']; //echo "test". $row_del['order_id']; $qry_del="DELETE from order_detail_table where order_id='$order_id' AND product_name='$product_name'"; echo $qry_del; if(mysql_query($qry_del)) { $msg="item deleted success"; } else { $msg="item not deleted"; } } ?> Like i have product name nokia on no.1 and samsung on no.2. when i echo the result after clicking delete button on samsung i get <?php DELETE from order_detail_table where order_id='67' AND product_name='nokia' ?> vineet Link to comment https://forums.phpfreaks.com/topic/133446-problem-deleting-particular-row-record/#findComment-694104 Share on other sites More sharing options...
zenag Posted November 20, 2008 Share Posted November 20, 2008 ur code seems to produce single result since u have not used loop while($row_del=mysql_fetch_array($result_del)) { $qry_del="DELETE from order_detail_table where order_id='$order_id' AND product_name='$product_name'"; echo $qry_del; } Link to comment https://forums.phpfreaks.com/topic/133446-problem-deleting-particular-row-record/#findComment-694108 Share on other sites More sharing options...
gmcalp Posted November 20, 2008 Share Posted November 20, 2008 Here's the delete from table that I have in one of my scripts: while ($row = mysql_fetch_array($result)) { $jobid = $row['id']; $jobtitle = $row['title']; $added = $row['added']; $empl = $row['employer']; echo '<p>' . $jobtitle . ", " . $empl . ": " . $added . ' <a href="' . $_SERVER['PHP_SELF'] . '?deletejob=' . $jobid . '">' . 'Delete this job</a></p>';} } // If a job has been deleted, // remove it from the database. if (isset($_GET['deletejob'])) { $jobid = $_GET['deletejob']; $sql = "DELETE FROM jobs WHERE id=$jobid"; if (@mysql_query($sql)) { echo "<b>Job Deleted!<br>You'll be redirected to Home Page after (4) Seconds"; #header("location: deleted.php"); echo "<meta http-equiv=Refresh content=4;url=".$_SERVER['PHP_SELF'].">"; # $_SERVER['PHP_SELF']; Edit it as you need. Link to comment https://forums.phpfreaks.com/topic/133446-problem-deleting-particular-row-record/#findComment-694111 Share on other sites More sharing options...
vinpkl Posted November 20, 2008 Author Share Posted November 20, 2008 hi gmcalp thanks for reply. The problem is that when i need to delete all products of one id in single click then it works fine. The delete button deletes all products of same id. I need to delete the particular item of that id. here i am facing trouble. vineet Here's the delete from table that I have in one of my scripts: while ($row = mysql_fetch_array($result)) { $jobid = $row['id']; $jobtitle = $row['title']; $added = $row['added']; $empl = $row['employer']; echo '<p>' . $jobtitle . ", " . $empl . ": " . $added . ' <a href="' . $_SERVER['PHP_SELF'] . '?deletejob=' . $jobid . '">' . 'Delete this job</a></p>';} } // If a job has been deleted, // remove it from the database. if (isset($_GET['deletejob'])) { $jobid = $_GET['deletejob']; $sql = "DELETE FROM jobs WHERE id=$jobid"; if (@mysql_query($sql)) { echo "<b>Job Deleted!<br>You'll be redirected to Home Page after (4) Seconds"; #header("location: deleted.php"); echo "<meta http-equiv=Refresh content=4;url=".$_SERVER['PHP_SELF'].">"; # $_SERVER['PHP_SELF']; Edit it as you need. Link to comment https://forums.phpfreaks.com/topic/133446-problem-deleting-particular-row-record/#findComment-694118 Share on other sites More sharing options...
vinpkl Posted November 20, 2008 Author Share Posted November 20, 2008 ur code seems to produce single result since u have not used loop while($row_del=mysql_fetch_array($result_del)) { $qry_del="DELETE from order_detail_table where order_id='$order_id' AND product_name='$product_name'"; echo $qry_del; } hi zenag i tried putting while loop. but it gaves me same result. it also deletes the product at no.1 not the particular product selected. <?php if(isset($_REQUEST['del_item_x'])) { $qry_del="select * from order_detail_table"; $result_del=mysql_query($qry_del); $row_del=mysql_fetch_array($result_del); $order_id=$row_del['order_id']; $product_name=$row_del['product_name']; //echo "test". $row_del['order_id']; while($row_del=mysql_fetch_array($result_del)) { $qry_del="DELETE from order_detail_table where order_id='$order_id' AND product_name='$product_name'"; echo $qry_del; } //echo $qry_del; if(mysql_query($qry_del)) { $msg="item deleted success"; } else { $msg="item not deleted"; } } ?> vineet Link to comment https://forums.phpfreaks.com/topic/133446-problem-deleting-particular-row-record/#findComment-694126 Share on other sites More sharing options...
zenag Posted November 20, 2008 Share Posted November 20, 2008 can u show the form u used to post these values Link to comment https://forums.phpfreaks.com/topic/133446-problem-deleting-particular-row-record/#findComment-694133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.