Im back! lol Im trying to make an added feature to my script Im making. The script adds "items" to different columns of different tables of a database, and then lets you display the table, and if you click one of the headers it sorts the list alphabetically from that column.

What I want to do is make it so you can also click each row of the table and it will make a pop up box that says "Are you Sure you Want to Delete this Row" and then a yes or no. Yes will delete that row and no will just close the pop up.

This probably requires javascript but how would I got about doing this? Heres the code of displaying part.

/* now grab the first row and start the table */
$row = mysql_fetch_assoc ($result);
echo "<TABLE width=80% cellspacing=1 cellpadding=5 bgcolor=#000000 border=0>\n";
echo "<TR>\n";
foreach ($row as $heading=>$column) {
    /* check if the heading is in our allowed_order
     * array. If it is, hyperlink it so that we can
     * order by this column */
    echo "<a href=index.php?displaytable=$displaytable&order_by=$heading><TD bgcolor=#343941 onmouseout=style.backgroundColor='#343941'; onmouseover=style.backgroundColor='#383E47'; style.cursor='hand'><b>";
    if (in_array ($heading, $allowed_order)) {
        echo "<font face=Verdana size=2 color=#CCCCCC>$heading</font>";
    } else {
        echo "<font face=Verdana size=2 color=#CCCCCC>$heading</font>";
    }                
echo "</b></TD></a>\n"; } echo "</TR>\n"; /* reset the $result set back to the first row and * display the data */ mysql_data_seek ($result, 0); while ($row = mysql_fetch_assoc ($result)) { echo "<TR bgcolor=#3E434D>\n"; foreach ($row as $column) { echo "<TD><font face=Verdana size=1 color=#CCCCCC><strong>$column</strong></font></TD>\n"; } echo "</TR>\n"; } echo "</TABLE>\n";

    Try something like -

    <a href="link_url" onClick="return confirm('Are you sure you want to delete blah?')">Delete</a>

    Hope this helps 😉

      hmmmm not really, I tried it and it doesnt even make the pop up box... and I need it to actually delete if confirmed.

        It works fine as long as you get the " and ' printing correctly.

        I use it daily. :rolleyes:

          mysql_data_seek ($result, 0);
          while ($row = mysql_fetch_assoc ($result)) {
              echo "<TR bgcolor=#3E434D>\n";
              foreach ($row as $column) {
                 echo "<TD><font face=Verdana size=1 color=#CCCCCC><strong><a href="index.php" onClick="return confirm('Are you sure you want to delete blah?')">$column</a></strong></font></TD>\n";
              }
              echo "</TR>\n";
          }
          echo "</TABLE>\n";
          

          gives me this error

          Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/virtual/site34/fst/var/www/html/items/index.php on line 238

          Line 238 being

          echo "<TD><font face=Verdana size=1 color=#CCCCCC><strong><a href="index.php" onClick="return confirm('Are you sure you want to delete blah?')">$column</a></strong></font></TD>\n";

            You must escape double quotes if used in a string quoted with double quotes -

            echo "<TD><font face=Verdana size=1 color=#CCCCCC><strong><a href=\"index.php\" onClick=\"return confirm('Are you sure you want to delete blah?')\">$column</a></strong></font></TD>\n";

            Hope this helps 😉

              ok now that works.... but how do I get it so when you do click yes it actually deletes that row??

                Ok nm, but what is the query to run that deletes a specific row (determined by a variable) from the table (also a variable)

                  DELETE FROM your_table WHERE id='7'

                  will delete the row that contains a 7 in the id field.

                  Cgraz

                    in my case I put

                    DELETE FROM $displaytable WHERE id='$id'

                    but it still doesnt work, maybe its having trouble transfering to the delete bit of the PHP

                      When you write your query use code like this which will give you meaningful errors if it fails -

                      $sql = "DELETE FROM $displaytable WHERE id='$id'";
                      $res = mysql_query($sql, $db) or die('Delete query failed.<br>MySQL error: ' . mysql_error() . '<br>Query: ' . $sql);

                      This should give you help in finding out why your query fails.

                      Hope this helps 😉

                        Write a Reply...