How do I delete a row when multiple rows have the same id

tru

I have a 2 tables, users and short_style.

Fields of table users:

id int  primary  not null auto increment
username
password
firstname
lastname

data inserted by users to table users:

users
id     username     password     firstname     lastname   
1      jsmith       md5hash      john          smith 
2      jbrown       md5hash      jane          brown 

data inserted by users to table short_style:

short_style
id     style_name     style_cost     style_time     number_of_styles   
1      bald           10             30             1
2      wash           5              15             2   
1      shave          12             30             3   
2      line           8              15             4   
1      wash           Free           15             6   
2      color          20             30             7   

I can have the users add a new style, that code works perfect.

I can have the users update their data as well, that code works perfect.

I'm stuck at deleting user data as I have no idea how to target the number_of_styles data, as that is the only unique data.

From what I have learned (in this short time) the DELETE only take 2 parameters, the Table name and the Table row (I'm assuming).

How can I make this work?

Sorry for the long html, I still haven't figured out how to show html in the comments. What I have:

<?php
if (isset($_POST['delete_servicename'])&&
isset($_POST['update_category'])) {

$delete_servicename = $_POST['delete_servicename'];
$category = $_POST['update_category'];

$atta = '_name';
$delete = "$category$atta";

$query = "SELECT $delete  FROM $category     WHERE `id`='".$_SESSION['user_id']."'";
$query_run = mysql_query($query);
if(mysql_num_rows($query_run)==1) {
$dquery = "DELETE FROM $category WHERE $id = '".$_SESSION['user_id']."'";
 }
}
?>

<form action="services_update.php" method="POST">
  <div class="a_u_d_sort">
    <ul>
      <li class="a_u_d_sort_left">
        <p>Category:</p>
      </li>

      <li class="a_u_d_sort_right">
        <select name="update_category">
          <option value="">select</option>
          <option value="short_style">Short Style</option>
          <option value="medium_style">Medium Style</option>
          <option value="long_style">Long Style</option>
          <option value="other_services">Other Service</option>
        </select>
      </li>
     </ul>
   </div>
   <div class="a_u_d_sort">
    <ul>
      <li class="a_u_d_sort_left">
        <p>Service Name:</p>
      </li>

      <li class="a_u_d_sort_right">
        <input type="text" name="delete_servicename"></input>
      </li>
     </ul>
    </div>
    <button class="add" type="submit">Delete</button>
  </form>
I wrestled a bear once.

You should ALWAYS use an auto-increment field for every table you create so that you always have a unique ID to use when deleting rows.

If that's not an option for you, you'll have to modify your delete query to make sure you're deleting the correct row:

$dquery = "DELETE FROM $category WHERE $id = '".$_SESSION['user_id']."' AND `style_name` = $stylename AND style_cost = $stylecost AND style_time = $styletime AND number_of_styles = $numberofstyles LIMIT 1";

Edit

I didn't not realize your number_of_styles was auto increment. In that case you can simply:

$dquery = "DELETE FROM $category WHERE number_of_styles = $numberofstyles LIMIT 1";

Since it's unique there would be no need to mention all the other fields.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL; Make a single row if multiple rows have the same id

From Dev

How do I delete rows which have the same entries in both columns?

From Dev

how I can delete multiple rows with same id like in android sqlite

From Dev

how to display multiple rows in one row with same id in mysql?

From Dev

how to display multiple rows in one row with same id in mysql?

From Dev

MYSQL update a row if all multiple rows that belong to the same foreign ID have same value

From Dev

How do I delete rows using row numbers in R?

From Dev

How do I have a floating delete row button for a DataGrid in WPF?

From Dev

How do I select distinct ID when ID could have multiple values

From Dev

How do I select distinct ID when ID could have multiple values

From Dev

Merge multiple rows with same ID into one row

From Dev

SQLite select query to get one row from multiple rows have same id

From Dev

How to delete Excel row if 2 columns have same value on different rows?

From Dev

How do I delete multiple rows from a table on Backand?

From Dev

How do i delete Multiple Row of Record in this code

From Dev

How do I flatMap a row of arrays into multiple rows?

From Dev

How do I split one row into multiple rows with Excel?

From Dev

How do i split a single row of columns into multiple rows and columns?

From Dev

How do I convert multiple rows into a single row

From Dev

How do I post my blobs into different rows on the same id?

From Dev

How to select an id through a class when you have multiple elements in the same page that have same class

From Dev

How to apply condition on rows that have the same ID?

From Dev

How to delete row which contains specific id as text if I have table id tag?

From Dev

Why do I have to run my for each loop multiple times to delete rows in a table?

From Dev

Delete multiple rows while using the id from the row before

From Dev

How do I run multiple processes with the same process group id?

From Dev

Delete with multiple where on different rows for same id - MySQL

From Dev

how to merge multiple rows with same id mysql

From Dev

how do i group rows by an id row in group_concat into one row string?

Related Related

  1. 1

    MySQL; Make a single row if multiple rows have the same id

  2. 2

    How do I delete rows which have the same entries in both columns?

  3. 3

    how I can delete multiple rows with same id like in android sqlite

  4. 4

    how to display multiple rows in one row with same id in mysql?

  5. 5

    how to display multiple rows in one row with same id in mysql?

  6. 6

    MYSQL update a row if all multiple rows that belong to the same foreign ID have same value

  7. 7

    How do I delete rows using row numbers in R?

  8. 8

    How do I have a floating delete row button for a DataGrid in WPF?

  9. 9

    How do I select distinct ID when ID could have multiple values

  10. 10

    How do I select distinct ID when ID could have multiple values

  11. 11

    Merge multiple rows with same ID into one row

  12. 12

    SQLite select query to get one row from multiple rows have same id

  13. 13

    How to delete Excel row if 2 columns have same value on different rows?

  14. 14

    How do I delete multiple rows from a table on Backand?

  15. 15

    How do i delete Multiple Row of Record in this code

  16. 16

    How do I flatMap a row of arrays into multiple rows?

  17. 17

    How do I split one row into multiple rows with Excel?

  18. 18

    How do i split a single row of columns into multiple rows and columns?

  19. 19

    How do I convert multiple rows into a single row

  20. 20

    How do I post my blobs into different rows on the same id?

  21. 21

    How to select an id through a class when you have multiple elements in the same page that have same class

  22. 22

    How to apply condition on rows that have the same ID?

  23. 23

    How to delete row which contains specific id as text if I have table id tag?

  24. 24

    Why do I have to run my for each loop multiple times to delete rows in a table?

  25. 25

    Delete multiple rows while using the id from the row before

  26. 26

    How do I run multiple processes with the same process group id?

  27. 27

    Delete with multiple where on different rows for same id - MySQL

  28. 28

    how to merge multiple rows with same id mysql

  29. 29

    how do i group rows by an id row in group_concat into one row string?

HotTag

Archive