select and delete

danielneridanielneri WP V.I.P.VPS - Virtual Prince of the Server
can someone provide a small script which shows multiple stuff being selected and then deleting on those selected?
ban1.gif

Comments

  • pfgannonpfgannon Moderator Administrator
    I honestly have no idea what you're talking about.
    Please elaborate.
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    okay so i have a script which uses a database to display a set of articles kindoff like a news script.

    i want to add a little admin panel addon to the script, where it adds new articles, and deletes existing articles.

    i want to know how to delete CERTAIN articles using DELETE FROM

    any ideas?
    ban1.gif
  • FelixFelix Junior Member Shared Hoster
    Hmm I think I understand what you want. Being able to select articles by clicking on a checkbox and then those selected will be deleted, right? First of all setup your form and checkboxes, making sure the names of the checkboxes are all the same but they have different values...

    [HTML]
    <form action="script.php" method="post">
    <!-- ALL YOUR OTHER FORM DATA BEFORE -->
    <input type="checkbox" name="checkboxes[]" value="1" />
    <input type="checkbox" name="checkboxes[]" value="2" />
    <!-- ALL OTHER FORM DATA AFTER -->
    <input type="submit" name="submit" value="Submit" />
    </form>
    [/HTML]

    Once that data has been submitted you will do something similar to the following.

    [PHP]
    <?php
    /* Check if data has been submitted... */
    if(isset($_POST))
    {
    /* Ensure at least one checkbox from the group was checked */
    if(isset($_POST))
    {
    /* Loop through and do as you please! */
    foreach($_POST as $box)
    {
    echo $box;
    }
    }
    }
    ?>
    [/PHP]

    Of course replace the "echo $box;" code with your own database code :D
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    thank you soo much felix!!

    will try the code out asap!
    ban1.gif
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    alright so heres what ive come up with so far:

    the main deleting page
    [PHP]<?php



    include ("dbconnect.php");

    $tresult = mysql_query("SELECT title, message FROM tutorials") or die(mysql_error());
    while($titmess= mysql_fetch_row($tresult)) {
    echo "<table border='1'>";
    echo "<tr> <th>Title, Message</th>";
    echo "<td align='left'>$titmess[0]</td>";
    echo "<td>$titmess[1]</td>";
    echo "</tr>";
    echo "</table>";

    }

    ?>[/PHP]

    end

    im not sure how to put the checkboxes into a php page, and dont know how to put the php mysql data into html :confused:


    im using your processing script, never actually been able to use it! ^
    |
    |

    anyways heres the slightly modified script, though i dont think it will work


    process.php
    [PHP]<?php
    /* Check if data has been submitted... */
    if(isset($_POST))
    {
    /* Ensure at least one checkbox from the group was checked */
    if(isset($_POST))
    {
    /* Loop through and do as you please! */
    foreach($_POST as $box)
    {
    $delete = mysql_query(DELETE $box FROM tutorial);
    if (!$delete) {
    die('Invalid query: ' . mysql_error());
    mysql_query($delete)
    else echo "Query Succesfully executed."
    }
    }
    [/PHP]
    end


    thanks sooo much for your help again!!!
    ban1.gif
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    ok after alot of playing around i managed to come up with this:

    deleting sript:

    [PHP]<?php



    include ("dbconnect.php");

    $titleresult = mysql_query("SELECT * FROM tutorials") or die(mysql_error());
    while($title = mysql_fetch_object($titleresult)) {




    ?>

    <html>
    <head>
    <title>VC Delete Script v0.1</title>
    </head>
    <body>
    <form method="post" action="process.php">




    <a><input type="checkbox" name="checkboxes[]" value="1"><?php
    echo "Title: $title->title<br>\n";
    ?></a>
    <a><?php
    echo "Message: $title->message<br>\n";
    ?>
    </a>
    <?php
    }
    ?>
    <input type="submit" name="submit" value="Submit" />
    </form>
    </body>
    </html>[/PHP]

    it serves the purpose of properly displaying the data, but since all the rows are on 1 checkbox, process.php deletes EVERYTHING from the database.

    I want to know how to select just one row and then display it with a checkbox in front of it, so on etc.

    any ideaS?:confused: :confused: :confused: :confused:
    ban1.gif
  • FelixFelix Junior Member Shared Hoster
    Oh yeah sorry I forgot to mention that you need to check if the current checkbox value is empty. Simply add this code below the foreach statement in the delete script.

    if(empty($box))
    {
    // SIMPLY DO NOTHING
    } else {
    // EXECUTE OTHER CODE HERE
    }

    :D
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    but like i said b4
    it serves the purpose of properly displaying the data, but since all the rows are on 1 checkbox, process.php deletes EVERYTHING from the database.

    I want to know how to select just one row and then display it with a checkbox in front of it, so on etc.

    any ideaS?
    ban1.gif
  • FelixFelix Junior Member Shared Hoster
    Well you would query the database and then simply loop through the result set using while() and then output your data....
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    you lost me at query lol

    could you give me a sample script?

    thanks a million
    ban1.gif
  • FelixFelix Junior Member Shared Hoster
    Oops I completely forgot about this. >_<

    How about talking to me on MSN or something dude? I'll show you something I have made and then you can tell me if thats what you are aiming for. :D
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    so i need one html form and php processor right
    ban1.gif
Sign In or Register to comment.