SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2002
    Location
    london
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help needed to print results of a query

    hi people

    i have a form which goes a bit like this

    i didnt include everything - just the important stuff...


    PHP Code:
    while(list($id,$comment) = @each($disp_array)) { ?>
    <tr><td>Date added:<?= $comment[dte?></td><td align='center' rowspan='5'><input type="checkbox" name="delete[<?= $id ?>]" value="yes"></td></tr>
    <tr><td><input name="comm[<?= $id ?>]" size="30" maxlength="70" value="<?= $comment[name?>"></td></tr>
    <tr><td><input name="comm[<?= $id ?>]" size="30" maxlength="70" value="<?= $comment[mail?>"></td></tr>
    <tr><td><input name="comm[<?= $id ?>]" size="30" maxlength="70" value="<?= $comment[site?>"></td></tr>
    <tr><td><TEXTAREA NAME="comm[<?= $id ?>]" ROWS=4 COLS=26 WRAP="virtual"><?= $comment[comm?></TEXTAREA></td></tr>
    <? ?>
    its used to display guestbook entries.

    for every row in the database it prints four textboxes plus one checkbox.

    i have this other script which i have been using to delete entries. its like this...

    PHP Code:
    //delete entries
      
    while(list($id,$flag) = @each($delete)) {
        if (
    $flag == "yes") {
          
    $query "DELETE FROM $table_name WHERE commentid = $id";
              
    $res mysql_query($query);
    }

    this basically checks the id assigned to the checkboxes that are highlighted and deletes the row with that id.

    what i would like to do is print out a sort of report on what was deleted. but not using just the id. id like it to look like...

    you deleted:
    Joe
    Joe@joe.com
    http://www.joe.com
    Hi, this is Joe!

    from the database

    for each entry that is deleted.

    anyone know how to achieve that?
    give me all your lentils

  2. #2
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change your code to something more like this:
    PHP Code:
    //delete entries
      
    $deletelist '0';
      while(list(
    $id,$flag) = @each($delete)) {
        if (
    $flag == "yes") {
          
    $query "DELETE FROM $table_name WHERE commentid = $id";
          
    $res mysql_query($query);
          
    $deletelist .= ',' $id;
        }
      } 
    then you have a variable ($deletelist) that contains all the ID's of the comments you have deleted, for example:
    Code:
    0,2,4,6,7,9,12,21
    (note the 0 in the beginning. I hope you don't have any comment with the ID 0)

    And now, all you need to do is:
    PHP Code:
    // show deleted comments
      
    $query "SELECT * FROM $table_name WHERE commentid IN (".$deletelist.")";
      
    $rows mysql_query($query);
      
    // and this is where you loop through them and show their info :) 

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how ya gonna show the deleted entries when they're already deleted?

    instead of having your inputs named delete[x] and a value of "yes", i'd name them delete[] with a value of "x", where x is the comment_id. then do something like this:

    PHP Code:
    $deletelist implode(','$HTTP_POST_VARS['delete']);
    $r mysql_query("SELECT * FROM $table_name WHERE commentid IN (0$deletelist)");

    while (
    $row mysql_fetch_array($r))
    {
    // display stuff or whatever
    }

    mysql_query("DELETE FROM $table_name WHERE commentid IN (0$deletelist)"); 
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2002
    Location
    london
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, thanks for your reply

    i worked out how to do it

    they are named delete[$id]

    and i printed the deleted entry almost exactly like you said right there

    give me all your lentils

  5. #5
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by DR_LaRRY_PEpPeR
    how ya gonna show the deleted entries when they're already deleted?
    D'uh.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •