SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Modifying Data in Table

    Hi,

    How do you modify data in a table?

    Is it possible to delete an entire row of dat from a table?

    Thanks
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  2. #2
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure. Just use
    DELETE [columnname] FROM tablename WHERE somecolumnname='data-from-the-row-you-want-to-delete'
    So if I have a table 'addbook':

    name | address | zipcode
    john | 1234 lane | 66345
    jane | 1435 lane | 77564
    joel | 1534 lane | 88678

    and I wanted to delete Joel's info, I would do
    DELETE FROM addbook WHERE name='joel'
    or I could do
    DELETE FROM addbook WHERE zipcode='88678'
    or if I wanted to just erase his address:
    DELETE address FROM addbook WHERE name='joel'

    To modify data, as in change it but not delete it, you use UPDATE like so:
    UPDATE tablename SET columnname='value' WHERE othercolumnname='value-in-row-you-want-to-modify'
    So following the example from above, if I need to change Jane's zipcode:
    UPDATE addbook SET zipcode='66243' WHERE name='jane'
    Kevin

  3. #3
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you so much!
    now..how do i run the mysql query?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL lynimz you need to read a good tutorial on using MySQL in your php

    Here is an example:
    PHP Code:

    file dbconnect.inc
    ----------------
    <?php // dbconnect.inc

    $dbcon mysql_connect("localhost""uid""pword");
    mysql_select_db("dbname"$dbcon);
    ?>

    file script.php
    ---------------
    <?php // script.php
    include("dbconnect.inc");

    $foo 'foo';

    $sql "DELETE FROM tableName
                 WHERE fieldName = '
    $foo'";

    $result mysql_query($sql);

    if ( ! 
    $result) {
       
    // Housten, we have a problem!
       // The mysql server could not process our query
       // So I'll echo the sql string for debugging purposes
       
    echo $sql;
    } else {
       
    // this will tell you how many rows were deleted
       
    $numDeleted mysql_num_affected();
    }
    ?>
    Note that as many scripts are often writen to access the same database, most coders will place the database connection code in a seperate file and include it in their script as I show above.

    Cheers
    Last edited by freakysid; Jun 13, 2001 at 04:00.

  5. #5
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well if you are building a PHP script, you would do
    PHP Code:
    mysql_query("DELETE FROM...rest of query"); 
    or you could use phpMyAdmin, and click on the database name and then in the box on the right side that says "query to run on xxx database" put the query in the box.
    Kevin

  6. #6
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol

    Did I say I know PHP/mySQL? LOL
    I'm learning!!! hehez

    Right. Got it! Thank You GUYS! Owe you tons. hehez
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein


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
  •