Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8002953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:31:31+00:00 2026-06-04T16:31:31+00:00

earlier i posted a question about getting a single constant value from a loop

  • 0

earlier i posted a question about getting a single constant value from a loop and use it outside of the loop (reference : Question).
now i’m facing another problem with another while loop.
it goes like this:
i have a query:

$sql = "
        SELECT alarms.id, alarms.date, clients.name, clients.number, alarms.controller, 
        alarmstype.type, alarms.alarmstatus, alarms.starttime, alarms.endtime
        FROM alarms
        INNER JOIN clients ON alarms.clientid = clients.id 
        INNER JOIN alarmstype ON alarms.typeid = alarmstype.id
        WHERE alarms.alarmstatus = 'ON' ORDER BY alarms.date ASC";
$result = mysql_query($sql);

and for each row i have assinged a button in the while loop:

      while ($row = mysql_fetch_array($result)) {
      print "<tr>
      <td>" . $row['date'] . "</td>
      <td>" . $row['number'] . " | " . $row['name'] . "</td>
<td>" . $row['controller'] . "</td>
    <td>" . $row['type'] . "</td>
    <td style='color: red'>
        <select name = 'statusupdate' style='font-size:10px;'>
          <option> " . $row['alarmstatus'] . " </option>
            <option> OFF </option>
        </select>
      </td>
            <td>" . $row['starttime'] . "</td>
            <td>" . $row['endtime'] . "</td>
            <td><input type='submit' name='delete' value='delete' /></td>

so far so good. The rows are displayed fine and the button’s there.
(all of the while loop is in a form tag so inputs are cool.
any way.
i want to make something like this:

 }
    if (isset($_POST['delete'])) {
      delete_alarm_from_database($alarmid)
    }

and the function goes like this:

function delete_alarm_from_database($id) {
  //find alarm by id and delete:
  $sql = "SELECT * FROM alarms WHERE id = " . $id;
  $result = mysql_result($sql);
  if (!$result) {
    print "couldn't find record.";
  }
  //delete record from database:
  else {
    $sql = "DELETE FROM alarms WHERE id = " . $id;
    $result = mysql_result($sql);
  }
}

my problem goes like this:
each row has an id but setting it as a variable will always overwrite until he puts in the variable the last id the loop reached. (meaning every delete button of each row will simply delete the last id each page load)

the question is like this. how can i make each delete button recognize it’s row id?

thanks in advance – Cheers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:31:32+00:00Added an answer on June 4, 2026 at 4:31 pm

    I suggest changing your process up a bit. Change the delete buttons to check boxes and allow the user to delete more than one at a time.

    Change

    <td><input type='submit' name='delete' value='delete' /></td>
    

    to

    <td><input type='checkbox' name='ids_to_delete[]' value='<?php echo $row['id']; ?>' /></td>
    

    Then add a new Delete button at the end of the table

    <input type='submit' name='delete' value='Delete selected rows' />
    

    Change your PHP to handle an array of values now

    if (isset($_POST['ids_to_delete']) && count($_POST['ids_to_delete']) > 0) {
        foreach($_POST['ids_to_delete'] as $alarmid) {
            delete_alarm_from_database($alarmid)
        }
    }
    

    or even better – change your delete_alarm_from_database function to handle an array and delete them all at once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I posted another question earlier about getting the arguments from a context menu App.
I posted a question earlier about stopping all sounds in a swf. Now, to
I posted a question about this earlier, but I have more information now and
I'm working from a question I posted earlier ( here ), and trying to
I posted a question similar to this earlier, however, after thinking about it and
Already i posted my earlier question about my FTP process (simple and short ),it
I'm trying to find a solution to a question I posted earlier about synchronizing
earlier today i posted a question on how to open an image from a
I posted a question earlier about why django redirect was not working correctly, but
I posted a question earlier about a div animation and I'm trying to modify

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.