• 26Dec

    In this tutorial I go over deleting rows, not only in PHPMyAdmin, but in PHP as well. Once rows are deleted, they are not coming back. On the side note, it is good to use something that is unique to every row when modifying them or deleting them. Otherwise you can delete anything that matches the name being “orange” and delete two rows. This is why I usually always have an ID field in my rows.
    This video tutorial goes over how to select rows from a database in PHPMyAdmin and then in PHP and then process the rows individually. Also this goes over ordering(ORDER) and limitation(LIMIT) in the SQL.
    You can find this tutorial video on youtube here.

    Source used after the jump;

    <?php
    $link = mysql_connect('localhost', 'phpuser', 'phppass');
    if (!$link) {
        die('Not connected : ' . mysql_error());
    }else{
        //echo "I am connected. ";
    }
    
    // make foo the current db
    $db_selected = mysql_select_db('test', $link);
    if (!$db_selected) {
        die ('Can\'t use test : ' . mysql_error());
    }
    if(isset($_REQUEST['del'])){
        //DELETE FROM `test`.`tableish` WHERE `tableish`.`ID` = 3
        $id = (int)$_REQUEST['del'];
        $sql = "DELETE FROM `tableish` WHERE `ID` = $id";
        mysql_query($sql);
    }
    $sql = "SELECT * FROM `tableish` ORDER BY `tableish`.`ID` ASC";
    $result = mysql_query($sql, $link);
    if(mysql_num_rows($result) > 0){
        while($row = mysql_fetch_array($result)){
            echo $row['name']."<a href=\"?del=".$row['ID']."\">Delete this row</a><br />\n";
        }
    }
    
    ?>
    

    Posted by Kloplop321 @ 10:39 am

    Tags: , ,

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.